dropzonejs-rails 0.3.0 → 0.3.1

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
- NzNjNTNmODFmNmVjOTJkNzNlMTVlY2E5YzhlMTJhMDdlNTE1ZGEwNQ==
4
+ YmRkMWIyNWYxMDJmZDQwYmMzZmE5ZjUzZTYwZjZhYTZkMDU1YmE0OQ==
5
5
  data.tar.gz: !binary |-
6
- NTIyM2U3YjFiZTg1NDlkZTY3OWIyZmJkMWNlZTIyOTYxNjQ5M2RjMg==
6
+ NGU5NzM5MjUzZmFjODc1NTI2MDIyNzU1ZTk0ZjRiNWYwNWRhYWE3MQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MWM3NmI5YjJlNTdkZjMyZDZhMmZlNmNlNzdkMWViZjMwOTgxNThhZDMyYmMw
10
- MmVjZWUzZDg1MWJjYjBmYmE2OTFhODM5MGVmY2RlY2JmNmU2MjdjNWM4Nzdi
11
- NWU5Yzc2OTlkNGMyZDU4YjNmYWRkY2I4MTcyODM3MWI3ZjNhMDk=
9
+ NTA3OTAyNTc2NGVkMjk5NzNlYzNhYmRiZGRjZDhjNWIxYWZiNjRkMzA5ZTVj
10
+ NzMxZTlhOTQzOTZkM2NhY2Y0NjljNDcxNTAwNzExMWQ1MTFjZDZlMzc2ZGI5
11
+ MzgzMzUyZWMyZDg3MDFmYzIzNjVmM2E5OTAwMDZkZDY2ZDBiMjY=
12
12
  data.tar.gz: !binary |-
13
- NjI2MDk3MjFkYWMwNTg3ODgzZTkwYzBmNWJjZWZkNDBkODYxMTE0OTM5ODk2
14
- MzI5MmQ5MGQxNGNkODM1ZDkwMDFlYjdlMzlmNDQ2YjY5MzY0ZTYwNDQwZmRl
15
- NTk2MzcyY2RkZjA4YjRhMjZhOGJmODhhYmM0OTQ2MDZiNTA4Mjc=
13
+ ZDUyNzFmZTg3ZjQ3MTA2MGQ4MzQ0N2Y2YmFlOTdlMDgwODhlZjdhMTgwYTVk
14
+ MmE5YmI4MTJhN2FhMmUwN2FjMmM1ZGY2MjBhNWY0OTAyNjJkZWY5MjM0Yzcx
15
+ OTY2ZjY5YzBkNzMyMTg4NWE5OWFiN2ZkNTQ5NjFkZmY1ODEwZTg=
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.0.1**.
7
+ The latest version of this gem bundles **Dropzone v3.1.0**.
8
8
 
9
9
  ## Installation and usage
10
10
 
@@ -1,4 +1,4 @@
1
1
  module DropzonejsRails
2
- VERSION = '0.3.0'
3
- DROPZONE_VERSION = '3.0.1'
2
+ VERSION = '0.3.1'
3
+ DROPZONE_VERSION = '3.1.0'
4
4
  end
@@ -472,6 +472,33 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
472
472
  }
473
473
  return this.element.appendChild(this.getFallbackForm());
474
474
  },
475
+ resize: function(file) {
476
+ var info, srcRatio, trgRatio;
477
+
478
+ info = {
479
+ srcX: 0,
480
+ srcY: 0,
481
+ srcWidth: file.width,
482
+ srcHeight: file.height
483
+ };
484
+ srcRatio = file.width / file.height;
485
+ trgRatio = this.options.thumbnailWidth / this.options.thumbnailHeight;
486
+ if (file.height < this.options.thumbnailHeight || file.width < this.options.thumbnailWidth) {
487
+ info.trgHeight = info.srcHeight;
488
+ info.trgWidth = info.srcWidth;
489
+ } else {
490
+ if (srcRatio > trgRatio) {
491
+ info.srcHeight = file.height;
492
+ info.srcWidth = info.srcHeight * trgRatio;
493
+ } else {
494
+ info.srcWidth = file.width;
495
+ info.srcHeight = info.srcWidth / trgRatio;
496
+ }
497
+ }
498
+ info.srcX = (file.width - info.srcWidth) / 2;
499
+ info.srcY = (file.height - info.srcHeight) / 2;
500
+ return info;
501
+ },
475
502
  /*
476
503
  Those functions register themselves to the events on init and handle all
477
504
  the user interface specific stuff. Overwriting them won't break the upload
@@ -670,6 +697,20 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
670
697
  eventName = _ref1[_i];
671
698
  this.on(eventName, this.options[eventName]);
672
699
  }
700
+ this.on("uploadprogress", function(file) {
701
+ var totalBytes, totalBytesSent, totalUploadProgress, _j, _len1, _ref2;
702
+
703
+ totalBytesSent = 0;
704
+ totalBytes = 0;
705
+ _ref2 = _this.files;
706
+ for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
707
+ file = _ref2[_j];
708
+ totalBytesSent += file.upload.bytesSent;
709
+ totalBytes += file.upload.total;
710
+ }
711
+ totalUploadProgress = 100 * totalBytesSent / totalBytes;
712
+ return _this.emit("totaluploadprogress", totalUploadProgress, totalBytes, totalBytesSent);
713
+ });
673
714
  noPropagation = function(e) {
674
715
  e.stopPropagation();
675
716
  if (e.preventDefault) {
@@ -886,6 +927,11 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
886
927
  Dropzone.prototype.addFile = function(file) {
887
928
  var _this = this;
888
929
 
930
+ file.upload = {
931
+ progress: 0,
932
+ total: file.size,
933
+ bytesSent: 0
934
+ };
889
935
  this.files.push(file);
890
936
  this.emit("addedfile", file);
891
937
  if (this.options.createImageThumbnails && file.type.match(/image.*/) && file.size <= this.options.maxThumbnailFilesize * 1024 * 1024) {
@@ -938,39 +984,22 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
938
984
 
939
985
  img = new Image;
940
986
  img.onload = function() {
941
- var canvas, ctx, srcHeight, srcRatio, srcWidth, srcX, srcY, thumbnail, trgHeight, trgRatio, trgWidth, trgX, trgY;
987
+ var canvas, ctx, resizeInfo, thumbnail, _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
942
988
 
989
+ file.width = img.width;
990
+ file.height = img.height;
991
+ resizeInfo = _this.options.resize.call(_this, file);
992
+ if ((_ref = resizeInfo.trgWidth) == null) {
993
+ resizeInfo.trgWidth = _this.options.thumbnailWidth;
994
+ }
995
+ if ((_ref1 = resizeInfo.trgHeight) == null) {
996
+ resizeInfo.trgHeight = _this.options.thumbnailHeight;
997
+ }
943
998
  canvas = document.createElement("canvas");
944
999
  ctx = canvas.getContext("2d");
945
- srcX = 0;
946
- srcY = 0;
947
- srcWidth = img.width;
948
- srcHeight = img.height;
949
- canvas.width = _this.options.thumbnailWidth;
950
- canvas.height = _this.options.thumbnailHeight;
951
- trgX = 0;
952
- trgY = 0;
953
- trgWidth = canvas.width;
954
- trgHeight = canvas.height;
955
- srcRatio = img.width / img.height;
956
- trgRatio = canvas.width / canvas.height;
957
- if (img.height < canvas.height || img.width < canvas.width) {
958
- trgHeight = srcHeight;
959
- trgWidth = srcWidth;
960
- } else {
961
- if (srcRatio > trgRatio) {
962
- srcHeight = img.height;
963
- srcWidth = srcHeight * trgRatio;
964
- } else {
965
- srcWidth = img.width;
966
- srcHeight = srcWidth / trgRatio;
967
- }
968
- }
969
- srcX = (img.width - srcWidth) / 2;
970
- srcY = (img.height - srcHeight) / 2;
971
- trgY = (canvas.height - trgHeight) / 2;
972
- trgX = (canvas.width - trgWidth) / 2;
973
- ctx.drawImage(img, srcX, srcY, srcWidth, srcHeight, trgX, trgY, trgWidth, trgHeight);
1000
+ canvas.width = resizeInfo.trgWidth;
1001
+ canvas.height = resizeInfo.trgHeight;
1002
+ ctx.drawImage(img, (_ref2 = resizeInfo.srcX) != null ? _ref2 : 0, (_ref3 = resizeInfo.srcY) != null ? _ref3 : 0, resizeInfo.srcWidth, resizeInfo.srcHeight, (_ref4 = resizeInfo.trgX) != null ? _ref4 : 0, (_ref5 = resizeInfo.trgY) != null ? _ref5 : 0, resizeInfo.trgWidth, resizeInfo.trgHeight);
974
1003
  thumbnail = canvas.toDataURL("image/png");
975
1004
  return _this.emit("thumbnail", file, thumbnail);
976
1005
  };
@@ -1026,7 +1055,6 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
1026
1055
  if (!((200 <= (_ref = xhr.status) && _ref < 300))) {
1027
1056
  return handleError();
1028
1057
  } else {
1029
- _this.emit("uploadprogress", file, 100, file.size);
1030
1058
  return _this.finished(file, response, e);
1031
1059
  }
1032
1060
  };
@@ -1035,7 +1063,15 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
1035
1063
  };
1036
1064
  progressObj = (_ref = xhr.upload) != null ? _ref : xhr;
1037
1065
  progressObj.onprogress = function(e) {
1038
- return _this.emit("uploadprogress", file, Math.max(0, Math.min(100, 100 * e.loaded / e.total)), e.loaded);
1066
+ var progress;
1067
+
1068
+ file.upload = {
1069
+ progress: progress,
1070
+ total: e.total,
1071
+ bytesSent: e.loaded
1072
+ };
1073
+ progress = 100 * e.loaded / e.total;
1074
+ return _this.emit("uploadprogress", file, progress, e.loaded);
1039
1075
  };
1040
1076
  xhr.setRequestHeader("Accept", "application/json");
1041
1077
  xhr.setRequestHeader("Cache-Control", "no-cache");
@@ -1086,7 +1122,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
1086
1122
 
1087
1123
  })(Em);
1088
1124
 
1089
- Dropzone.version = "3.0.1";
1125
+ Dropzone.version = "3.1.0";
1090
1126
 
1091
1127
  Dropzone.options = {};
1092
1128
 
@@ -215,11 +215,6 @@
215
215
  box-shadow: 1px 1px 4px rgba(0,0,0,0.16);
216
216
  font-size: 14px;
217
217
  }
218
- .dropzone .dz-preview .dz-details img,
219
- .dropzone-previews .dz-preview .dz-details img {
220
- width: 100px;
221
- height: 100px;
222
- }
223
218
  .dropzone .dz-preview.dz-image-preview:hover .dz-details img,
224
219
  .dropzone-previews .dz-preview.dz-image-preview:hover .dz-details img {
225
220
  display: block;
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.3.0
4
+ version: 0.3.1
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-05-13 00:00:00.000000000 Z
11
+ date: 2013-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails