dropzonejs-rails 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OThkY2Q2NjliYWY1Njk0Zjk5OTFmOTNlNGQ5NjAyY2I1OWRhOTU2ZQ==
4
+ ZmM3ZjJkYjI3ZGExYjlmZGU3ZWFiYjc1M2ZjOTgyODg4OGRlZDk0ZA==
5
5
  data.tar.gz: !binary |-
6
- NGFkNjZhZjdjYzU0NjQ4MzZlNWQxOWY0N2RjNjUwYTczYzA1ZWFjYQ==
6
+ Njc1ZjNkNjM5MjUzNTUzMDQxYmY1YTJhZTliMzQ3NGNlN2RlMTIwMg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NjgxN2MzOWMxYTc4NzZkNjkzZmUwOGI1N2U1YWIwYThjMzVmNmQzZjMxOTNj
10
- MzA1NzQzYjkyZWY3MjhjNzBlOGU5NzZmNmU2OGY3MjVlYzY5ZWFmNGMxNjIy
11
- NDM1NmIyZmZlMjc5M2MwZTU5YzM1MDZjY2ZjZWVkNDg4ZGVjOWY=
9
+ MDI5YzRkMjZlNTk2MzY3NTk0MzFkMjNjNmU0ODUwNGEwZjM3Nzg4ZDY5Njk3
10
+ YWNkNGNkOGVkMTVkMWU2MGExZDJmMGFhN2FlMTk1MDI5NDNhNzBmMTUxY2Jl
11
+ YTFlNWRiNWVmZjkxNGNjOTc4MzhkOTg0ZWQxYzUxNWUxMjJjMDY=
12
12
  data.tar.gz: !binary |-
13
- ODFkODVlOGIzMWU1MTI5YjdmMDMyYzU5ZjA1Yzk3NmZmMDBkMGY0ODUwMzU3
14
- MDJlNjFlM2RiNzdlY2Y1ZTc4ZmI2YWIzZTk5Mzg1MGIzOGRkMDYzNzkyMzI5
15
- MmM4Mzk5NzY3MjhkOWEyNjExMjcxMGJmZGRjYjBjYmQ5NjRlMDg=
13
+ NmM5MmVjNjA5NzM1OWQ3YTBhZjEzNjllYWU3MmU1MTk4OWIxOGUzYThiMzJj
14
+ YzljMjhkMTU0YzVkZGNkYzAwODU3ODJiNTAwZjJhN2JhZDRiNWVkZmY1NTc3
15
+ YzdmODJhNDc1ZmEyYTMxMWJiNTIyMmYxN2NkNGIyMjM5NDkzNzY=
data/README.md CHANGED
@@ -4,7 +4,7 @@ Integrate [Matias Meno's Dropzone](http://www.dropzonejs.com/) awesome file uplo
4
4
 
5
5
  ## Version
6
6
 
7
- The latest version of this gem bundles **Dropzone v3.4.1**.
7
+ The latest version of this gem bundles **Dropzone v3.5.1**.
8
8
 
9
9
  ## Installation and usage
10
10
 
@@ -1,4 +1,4 @@
1
1
  module DropzonejsRails
2
- VERSION = '0.4.2'
3
- DROPZONE_VERSION = '3.4.1'
2
+ VERSION = '0.4.3'
3
+ DROPZONE_VERSION = '3.5.1'
4
4
  end
@@ -388,8 +388,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
388
388
  var Dropzone, Em, camelize, contentLoaded, noop, without,
389
389
  __hasProp = {}.hasOwnProperty,
390
390
  __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
391
- __slice = [].slice,
392
- __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
391
+ __slice = [].slice;
393
392
 
394
393
  Em = typeof Emitter !== "undefined" && Emitter !== null ? Emitter : require("emitter");
395
394
 
@@ -427,6 +426,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
427
426
  acceptedMimeTypes: null,
428
427
  acceptParameter: null,
429
428
  enqueueForUpload: true,
429
+ addRemoveLinks: false,
430
430
  previewsContainer: null,
431
431
  dictDefaultMessage: "Drop files here to upload",
432
432
  dictFallbackMessage: "Your browser does not support drag'n'drop file uploads.",
@@ -434,6 +434,9 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
434
434
  dictFileTooBig: "File is too big ({{filesize}}MB). Max filesize: {{maxFilesize}}MB.",
435
435
  dictInvalidFileType: "You can't upload files of this type.",
436
436
  dictResponseError: "Server responded with {{statusCode}} code.",
437
+ dictCancelUpload: "Cancel upload",
438
+ dictCancelUploadConfirmation: "Are you sure you want to cancel this upload?",
439
+ dictRemoveFile: "Remove file",
437
440
  accept: function(file, done) {
438
441
  return done();
439
442
  },
@@ -447,7 +450,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
447
450
  _ref = this.element.getElementsByTagName("div");
448
451
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
449
452
  child = _ref[_i];
450
- if (/(^| )message($| )/.test(child.className)) {
453
+ if (/(^| )dz-message($| )/.test(child.className)) {
451
454
  messageElement = child;
452
455
  child.className = "dz-message";
453
456
  continue;
@@ -523,11 +526,27 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
523
526
  return this.element.classList.remove("dz-started");
524
527
  },
525
528
  addedfile: function(file) {
529
+ var _this = this;
526
530
  file.previewElement = Dropzone.createElement(this.options.previewTemplate);
527
531
  file.previewTemplate = file.previewElement;
528
532
  this.previewsContainer.appendChild(file.previewElement);
529
533
  file.previewElement.querySelector("[data-dz-name]").textContent = file.name;
530
- return file.previewElement.querySelector("[data-dz-size]").innerHTML = this.filesize(file.size);
534
+ file.previewElement.querySelector("[data-dz-size]").innerHTML = this.filesize(file.size);
535
+ if (this.options.addRemoveLinks) {
536
+ file._removeLink = Dropzone.createElement("<a class=\"dz-remove\" href=\"javascript:undefined;\">" + this.options.dictRemoveFile + "</a>");
537
+ file._removeLink.addEventListener("click", function(e) {
538
+ e.preventDefault();
539
+ e.stopPropagation();
540
+ if (file.status === Dropzone.UPLOADING) {
541
+ if (window.confirm(_this.options.dictCancelUploadConfirmation)) {
542
+ return _this.removeFile(file);
543
+ }
544
+ } else {
545
+ return _this.removeFile(file);
546
+ }
547
+ });
548
+ return file.previewElement.appendChild(file._removeLink);
549
+ }
531
550
  },
532
551
  removedfile: function(file) {
533
552
  var _ref;
@@ -546,7 +565,10 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
546
565
  return file.previewElement.querySelector("[data-dz-errormessage]").textContent = message;
547
566
  },
548
567
  processingfile: function(file) {
549
- return file.previewElement.classList.add("dz-processing");
568
+ file.previewElement.classList.add("dz-processing");
569
+ if (file._removeLink) {
570
+ return file._removeLink.textContent = this.options.dictCancelUpload;
571
+ }
550
572
  },
551
573
  uploadprogress: function(file, progress, bytesSent) {
552
574
  return file.previewElement.querySelector("[data-dz-uploadprogress]").style.width = "" + progress + "%";
@@ -556,7 +578,11 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
556
578
  success: function(file) {
557
579
  return file.previewElement.classList.add("dz-success");
558
580
  },
559
- complete: noop,
581
+ complete: function(file) {
582
+ if (file._removeLink) {
583
+ return file._removeLink.textContent = this.options.dictRemoveFile;
584
+ }
585
+ },
560
586
  previewTemplate: "<div class=\"dz-preview dz-file-preview\">\n <div class=\"dz-details\">\n <div class=\"dz-filename\"><span data-dz-name></span></div>\n <div class=\"dz-size\" data-dz-size></div>\n <img data-dz-thumbnail />\n </div>\n <div class=\"dz-progress\"><span class=\"dz-upload\" data-dz-uploadprogress></span></div>\n <div class=\"dz-success-mark\"><span>✔</span></div>\n <div class=\"dz-error-mark\"><span>✘</span></div>\n <div class=\"dz-error-message\"><span data-dz-errormessage></span></div>\n</div>"
561
587
  };
562
588
 
@@ -581,9 +607,6 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
581
607
  this.clickableElements = [];
582
608
  this.listeners = [];
583
609
  this.files = [];
584
- this.acceptedFiles = [];
585
- this.filesQueue = [];
586
- this.filesProcessing = [];
587
610
  if (typeof this.element === "string") {
588
611
  this.element = document.querySelector(this.element);
589
612
  }
@@ -628,14 +651,75 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
628
651
  this.init();
629
652
  }
630
653
 
654
+ Dropzone.prototype.getAcceptedFiles = function() {
655
+ var file, _i, _len, _ref, _results;
656
+ _ref = this.files;
657
+ _results = [];
658
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
659
+ file = _ref[_i];
660
+ if (file.accepted) {
661
+ _results.push(file);
662
+ }
663
+ }
664
+ return _results;
665
+ };
666
+
667
+ Dropzone.prototype.getRejectedFiles = function() {
668
+ var file, _i, _len, _ref, _results;
669
+ if (!file.accepted) {
670
+ _ref = this.files;
671
+ _results = [];
672
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
673
+ file = _ref[_i];
674
+ _results.push(file);
675
+ }
676
+ return _results;
677
+ }
678
+ };
679
+
680
+ Dropzone.prototype.getQueuedFiles = function() {
681
+ var file, _i, _len, _ref, _results;
682
+ _ref = this.files;
683
+ _results = [];
684
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
685
+ file = _ref[_i];
686
+ if (file.status === Dropzone.QUEUED) {
687
+ _results.push(file);
688
+ }
689
+ }
690
+ return _results;
691
+ };
692
+
693
+ Dropzone.prototype.getUploadingFiles = function() {
694
+ var file, _i, _len, _ref, _results;
695
+ _ref = this.files;
696
+ _results = [];
697
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
698
+ file = _ref[_i];
699
+ if (file.status === Dropzone.UPLOADING) {
700
+ _results.push(file);
701
+ }
702
+ }
703
+ return _results;
704
+ };
705
+
706
+ Dropzone.prototype.enqueueFile = function(file) {
707
+ if (file.status === Dropzone.ACCEPTED) {
708
+ file.status = Dropzone.QUEUED;
709
+ return this.processQueue();
710
+ } else {
711
+ throw new Error("This file can't be queued because it has already been processed or was rejected.");
712
+ }
713
+ };
714
+
631
715
  Dropzone.prototype.init = function() {
632
716
  var eventName, noPropagation, setupHiddenFileInput, _i, _len, _ref, _ref1,
633
717
  _this = this;
634
718
  if (this.element.tagName === "form") {
635
719
  this.element.setAttribute("enctype", "multipart/form-data");
636
720
  }
637
- if (this.element.classList.contains("dropzone") && !this.element.querySelector("[data-dz-message]")) {
638
- this.element.appendChild(Dropzone.createElement("<div class=\"dz-default dz-message\" data-dz-message><span>" + this.options.dictDefaultMessage + "</span></div>"));
721
+ if (this.element.classList.contains("dropzone") && !this.element.querySelector(".dz-message")) {
722
+ this.element.appendChild(Dropzone.createElement("<div class=\"dz-default dz-message\"><span>" + this.options.dictDefaultMessage + "</span></div>"));
639
723
  }
640
724
  if (this.clickableElements.length) {
641
725
  setupHiddenFileInput = function() {
@@ -676,18 +760,11 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
676
760
  eventName = _ref1[_i];
677
761
  this.on(eventName, this.options[eventName]);
678
762
  }
679
- this.on("uploadprogress", function(file) {
680
- var totalBytes, totalBytesSent, totalUploadProgress, _j, _len1, _ref2;
681
- totalBytesSent = 0;
682
- totalBytes = 0;
683
- _ref2 = _this.acceptedFiles;
684
- for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
685
- file = _ref2[_j];
686
- totalBytesSent += file.upload.bytesSent;
687
- totalBytes += file.upload.total;
688
- }
689
- totalUploadProgress = 100 * totalBytesSent / totalBytes;
690
- return _this.emit("totaluploadprogress", totalUploadProgress, totalBytes, totalBytesSent);
763
+ this.on("uploadprogress", function() {
764
+ return _this.updateTotalUploadProgress();
765
+ });
766
+ this.on("removedfile", function() {
767
+ return _this.updateTotalUploadProgress();
691
768
  });
692
769
  noPropagation = function(e) {
693
770
  e.stopPropagation();
@@ -745,13 +822,32 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
745
822
  Dropzone.prototype.destroy = function() {
746
823
  var _ref;
747
824
  this.disable();
748
- this.removeAllFiles();
825
+ this.removeAllFiles(true);
749
826
  if ((_ref = this.hiddenFileInput) != null ? _ref.parentNode : void 0) {
750
827
  this.hiddenFileInput.parentNode.removeChild(this.hiddenFileInput);
751
828
  return this.hiddenFileInput = null;
752
829
  }
753
830
  };
754
831
 
832
+ Dropzone.prototype.updateTotalUploadProgress = function() {
833
+ var acceptedFiles, file, totalBytes, totalBytesSent, totalUploadProgress, _i, _len, _ref;
834
+ totalBytesSent = 0;
835
+ totalBytes = 0;
836
+ acceptedFiles = this.getAcceptedFiles();
837
+ if (acceptedFiles.length) {
838
+ _ref = this.getAcceptedFiles();
839
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
840
+ file = _ref[_i];
841
+ totalBytesSent += file.upload.bytesSent;
842
+ totalBytes += file.upload.total;
843
+ }
844
+ totalUploadProgress = 100 * totalBytesSent / totalBytes;
845
+ } else {
846
+ totalUploadProgress = 100;
847
+ }
848
+ return this.emit("totaluploadprogress", totalUploadProgress, totalBytes, totalBytesSent);
849
+ };
850
+
755
851
  Dropzone.prototype.getFallbackForm = function() {
756
852
  var existingFallback, fields, fieldsString, form;
757
853
  if (existingFallback = this.getExistingFallback()) {
@@ -834,20 +930,15 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
834
930
  };
835
931
 
836
932
  Dropzone.prototype.disable = function() {
837
- var file, _i, _j, _len, _len1, _ref, _ref1, _results;
933
+ var file, _i, _len, _ref, _results;
838
934
  this.clickableElements.forEach(function(element) {
839
935
  return element.classList.remove("dz-clickable");
840
936
  });
841
937
  this.removeEventListeners();
842
- _ref = this.filesProcessing;
938
+ _ref = this.files;
939
+ _results = [];
843
940
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
844
941
  file = _ref[_i];
845
- this.cancelUpload(file);
846
- }
847
- _ref1 = this.filesQueue;
848
- _results = [];
849
- for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
850
- file = _ref1[_j];
851
942
  _results.push(this.cancelUpload(file));
852
943
  }
853
944
  return _results;
@@ -933,9 +1024,8 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
933
1024
  } else {
934
1025
  file.status = Dropzone.ACCEPTED;
935
1026
  file.accepted = true;
936
- _this.acceptedFiles.push(file);
937
1027
  if (_this.options.enqueueForUpload) {
938
- _this.filesQueue.push(file);
1028
+ file.status = Dropzone.QUEUED;
939
1029
  return _this.processQueue();
940
1030
  }
941
1031
  }
@@ -947,19 +1037,21 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
947
1037
  this.cancelUpload(file);
948
1038
  }
949
1039
  this.files = without(this.files, file);
950
- this.filesQueue = without(this.filesQueue, file);
951
1040
  this.emit("removedfile", file);
952
1041
  if (this.files.length === 0) {
953
1042
  return this.emit("reset");
954
1043
  }
955
1044
  };
956
1045
 
957
- Dropzone.prototype.removeAllFiles = function() {
1046
+ Dropzone.prototype.removeAllFiles = function(cancelIfNecessary) {
958
1047
  var file, _i, _len, _ref;
1048
+ if (cancelIfNecessary == null) {
1049
+ cancelIfNecessary = false;
1050
+ }
959
1051
  _ref = this.files.slice();
960
1052
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
961
1053
  file = _ref[_i];
962
- if (__indexOf.call(this.filesProcessing, file) < 0) {
1054
+ if (file.status !== Dropzone.UPLOADING || cancelIfNecessary) {
963
1055
  this.removeFile(file);
964
1056
  }
965
1057
  }
@@ -998,21 +1090,21 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
998
1090
  };
999
1091
 
1000
1092
  Dropzone.prototype.processQueue = function() {
1001
- var i, parallelUploads, processingLength;
1093
+ var i, parallelUploads, processingLength, queuedFiles;
1002
1094
  parallelUploads = this.options.parallelUploads;
1003
- processingLength = this.filesProcessing.length;
1095
+ processingLength = this.getUploadingFiles().length;
1004
1096
  i = processingLength;
1097
+ queuedFiles = this.getQueuedFiles();
1005
1098
  while (i < parallelUploads) {
1006
- if (!this.filesQueue.length) {
1099
+ if (!queuedFiles.length) {
1007
1100
  return;
1008
1101
  }
1009
- this.processFile(this.filesQueue.shift());
1102
+ this.processFile(queuedFiles.shift());
1010
1103
  i++;
1011
1104
  }
1012
1105
  };
1013
1106
 
1014
1107
  Dropzone.prototype.processFile = function(file) {
1015
- this.filesProcessing.push(file);
1016
1108
  file.processing = true;
1017
1109
  file.status = Dropzone.UPLOADING;
1018
1110
  this.emit("processingfile", file);
@@ -1024,11 +1116,11 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
1024
1116
  if (file.status === Dropzone.UPLOADING) {
1025
1117
  file.status = Dropzone.CANCELED;
1026
1118
  file.xhr.abort();
1027
- return this.filesProcessing = without(this.filesProcessing, file);
1028
- } else if ((_ref = file.status) === Dropzone.ADDED || _ref === Dropzone.ACCEPTED) {
1119
+ } else if ((_ref = file.status) === Dropzone.ADDED || _ref === Dropzone.ACCEPTED || _ref === Dropzone.QUEUED) {
1029
1120
  file.status = Dropzone.CANCELED;
1030
- return this.filesQueue = without(this.filesQueue, file);
1031
1121
  }
1122
+ this.emit("complete", file);
1123
+ return this.processQueue();
1032
1124
  };
1033
1125
 
1034
1126
  Dropzone.prototype.uploadFile = function(file) {
@@ -1131,8 +1223,6 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
1131
1223
  };
1132
1224
 
1133
1225
  Dropzone.prototype.finished = function(file, responseText, e) {
1134
- this.filesProcessing = without(this.filesProcessing, file);
1135
- file.processing = false;
1136
1226
  file.status = Dropzone.SUCCESS;
1137
1227
  this.processQueue();
1138
1228
  this.emit("success", file, responseText, e);
@@ -1141,8 +1231,6 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
1141
1231
  };
1142
1232
 
1143
1233
  Dropzone.prototype.errorProcessing = function(file, message, xhr) {
1144
- this.filesProcessing = without(this.filesProcessing, file);
1145
- file.processing = false;
1146
1234
  file.status = Dropzone.ERROR;
1147
1235
  this.processQueue();
1148
1236
  this.emit("error", file, message, xhr);
@@ -1153,7 +1241,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
1153
1241
 
1154
1242
  })(Em);
1155
1243
 
1156
- Dropzone.version = "3.4.1";
1244
+ Dropzone.version = "3.5.1";
1157
1245
 
1158
1246
  Dropzone.options = {};
1159
1247
 
@@ -1360,8 +1448,12 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
1360
1448
 
1361
1449
  Dropzone.ACCEPTED = "accepted";
1362
1450
 
1451
+ Dropzone.QUEUED = "queued";
1452
+
1363
1453
  Dropzone.UPLOADING = "uploading";
1364
1454
 
1455
+ Dropzone.PROCESSING = Dropzone.UPLOADING;
1456
+
1365
1457
  Dropzone.CANCELED = "canceled";
1366
1458
 
1367
1459
  Dropzone.ERROR = "error";
@@ -341,6 +341,28 @@
341
341
  -ms-filter: none;
342
342
  filter: none;
343
343
  }
344
+ .dropzone a.dz-remove,
345
+ .dropzone-previews a.dz-remove {
346
+ background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #fafafa), color-stop(1, #eee));
347
+ background-image: -webkit-linear-gradient(top, #fafafa 0%, #eee 100%);
348
+ background-image: -moz-linear-gradient(top, #fafafa 0%, #eee 100%);
349
+ background-image: -o-linear-gradient(top, #fafafa 0%, #eee 100%);
350
+ background-image: -ms-linear-gradient(top, #fafafa 0%, #eee 100%);
351
+ background-image: linear-gradient(top, #fafafa 0%, #eee 100%);
352
+ -webkit-border-radius: 2px;
353
+ border-radius: 2px;
354
+ border: 1px solid #eee;
355
+ text-decoration: none;
356
+ display: block;
357
+ padding: 4px 5px;
358
+ text-align: center;
359
+ color: #aaa;
360
+ margin-top: 26px;
361
+ }
362
+ .dropzone a.dz-remove:hover,
363
+ .dropzone-previews a.dz-remove:hover {
364
+ color: #666;
365
+ }
344
366
  @-moz-keyframes loading {
345
367
  0% {
346
368
  background-position: 0 -400px;
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dropzonejs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Nahuel Cuesta Luengo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-14 00:00:00.000000000 Z
11
+ date: 2013-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit