jquery.fileupload-rails 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Readme.md CHANGED
@@ -41,6 +41,8 @@ If you downloaded jquery.ui assets into your project, delete them and use [jquer
41
41
 
42
42
  ## Changelog
43
43
 
44
+ 1.3.0. Core 5.26.
45
+
44
46
  1.2.0. Core 5.21.1, demo instructions.
45
47
 
46
48
  1.1.1. Core 5.19.4, jQuery UI 1.9, added licensing info.
@@ -2,7 +2,6 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>Demo</title>
5
- <%= stylesheet_link_tag "application", :media => "all" %>
6
5
  <%= javascript_include_tag "application" %>
7
6
  <%= csrf_meta_tags %>
8
7
  </head>
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "jquery.fileupload-rails"
5
- s.version = "1.2.0"
5
+ s.version = "1.3.0"
6
6
  s.author = "Semyon Perepelitsa"
7
7
  s.email = "sema@sema.in"
8
8
  s.homepage = "https://github.com/semaperepelitsa/jquery.fileupload-rails"
@@ -2,7 +2,7 @@
2
2
  //= require jquery.iframe-transport
3
3
 
4
4
  /*
5
- * jQuery File Upload Plugin 5.21.1
5
+ * jQuery File Upload Plugin 5.26
6
6
  * https://github.com/blueimp/jQuery-File-Upload
7
7
  *
8
8
  * Copyright 2010, Sebastian Tschan
@@ -36,21 +36,6 @@
36
36
  $.support.xhrFileUpload = !!(window.XMLHttpRequestUpload && window.FileReader);
37
37
  $.support.xhrFormDataFileUpload = !!window.FormData;
38
38
 
39
- // The form.elements propHook is added to filter serialized elements
40
- // to not include file inputs in jQuery 1.9.0.
41
- // This hooks directly into jQuery.fn.serializeArray.
42
- // For more info, see http://bugs.jquery.com/ticket/13306
43
- $.propHooks.elements = {
44
- get: function (form) {
45
- if ($.nodeName(form, 'form')) {
46
- return $.grep(form.elements, function (elem) {
47
- return !$.nodeName(elem, 'input') || elem.type !== 'file';
48
- });
49
- }
50
- return null;
51
- }
52
- };
53
-
54
39
  // The fileupload widget listens for change events on file input fields defined
55
40
  // via fileInput setting and paste or drop events of the given dropZone.
56
41
  // In addition to the default jQuery Widget methods, the fileupload widget
@@ -130,6 +115,8 @@
130
115
  progressInterval: 100,
131
116
  // Interval in milliseconds to calculate progress bitrate:
132
117
  bitrateInterval: 500,
118
+ // By default, uploads are started automatically when adding files:
119
+ autoUpload: true,
133
120
 
134
121
  // Additional form data to be sent along with the file uploads can be set
135
122
  // using this option, which accepts an array of objects with name and
@@ -154,7 +141,11 @@
154
141
  // handlers using jQuery's Deferred callbacks:
155
142
  // data.submit().done(func).fail(func).always(func);
156
143
  add: function (e, data) {
157
- data.submit();
144
+ if (data.autoUpload || (data.autoUpload !== false &&
145
+ ($(this).data('blueimp-fileupload') ||
146
+ $(this).data('fileupload')).options.autoUpload)) {
147
+ data.submit();
148
+ }
158
149
  },
159
150
 
160
151
  // Other callbacks:
@@ -273,10 +264,17 @@
273
264
  return total;
274
265
  },
275
266
 
267
+ _initProgressObject: function (obj) {
268
+ obj._progress = {
269
+ loaded: 0,
270
+ total: 0,
271
+ bitrate: 0
272
+ };
273
+ },
274
+
276
275
  _onProgress: function (e, data) {
277
276
  if (e.lengthComputable) {
278
277
  var now = +(new Date()),
279
- total,
280
278
  loaded;
281
279
  if (data._time && data.progressInterval &&
282
280
  (now - data._time < data.progressInterval) &&
@@ -284,16 +282,19 @@
284
282
  return;
285
283
  }
286
284
  data._time = now;
287
- total = data.total || this._getTotal(data.files);
288
- loaded = parseInt(
289
- e.loaded / e.total * (data.chunkSize || total),
290
- 10
285
+ loaded = Math.floor(
286
+ e.loaded / e.total * (data.chunkSize || data._progress.total)
291
287
  ) + (data.uploadedBytes || 0);
292
- this._loaded += loaded - (data.loaded || data.uploadedBytes || 0);
293
- data.lengthComputable = true;
294
- data.loaded = loaded;
295
- data.total = total;
296
- data.bitrate = data._bitrateTimer.getBitrate(
288
+ // Add the difference from the previously loaded state
289
+ // to the global loaded counter:
290
+ this._progress.loaded += (loaded - data._progress.loaded);
291
+ this._progress.bitrate = this._bitrateTimer.getBitrate(
292
+ now,
293
+ this._progress.loaded,
294
+ data.bitrateInterval
295
+ );
296
+ data._progress.loaded = data.loaded = loaded;
297
+ data._progress.bitrate = data.bitrate = data._bitrateTimer.getBitrate(
297
298
  now,
298
299
  loaded,
299
300
  data.bitrateInterval
@@ -304,16 +305,7 @@
304
305
  this._trigger('progress', e, data);
305
306
  // Trigger a global progress event for all current file uploads,
306
307
  // including ajax calls queued for sequential file uploads:
307
- this._trigger('progressall', e, {
308
- lengthComputable: true,
309
- loaded: this._loaded,
310
- total: this._total,
311
- bitrate: this._bitrateTimer.getBitrate(
312
- now,
313
- this._loaded,
314
- data.bitrateInterval
315
- )
316
- });
308
+ this._trigger('progressall', e, this._progress);
317
309
  }
318
310
  },
319
311
 
@@ -498,6 +490,21 @@
498
490
  return options;
499
491
  },
500
492
 
493
+ // jQuery 1.6 doesn't provide .state(),
494
+ // while jQuery 1.8+ removed .isRejected() and .isResolved():
495
+ _getDeferredState: function (deferred) {
496
+ if (deferred.state) {
497
+ return deferred.state();
498
+ }
499
+ if (deferred.isResolved()) {
500
+ return 'resolved';
501
+ }
502
+ if (deferred.isRejected()) {
503
+ return 'rejected';
504
+ }
505
+ return 'pending';
506
+ },
507
+
501
508
  // Maps jqXHR callbacks to the equivalent
502
509
  // methods of the given Promise object:
503
510
  _enhancePromise: function (promise) {
@@ -522,6 +529,33 @@
522
529
  return this._enhancePromise(promise);
523
530
  },
524
531
 
532
+ // Adds convenience methods to the callback arguments:
533
+ _addConvenienceMethods: function (e, data) {
534
+ var that = this;
535
+ data.submit = function () {
536
+ if (this.state() !== 'pending') {
537
+ data.jqXHR = this.jqXHR =
538
+ (that._trigger('submit', e, this) !== false) &&
539
+ that._onSend(e, this);
540
+ }
541
+ return this.jqXHR || that._getXHRPromise();
542
+ };
543
+ data.abort = function () {
544
+ if (this.jqXHR) {
545
+ return this.jqXHR.abort();
546
+ }
547
+ return this._getXHRPromise();
548
+ };
549
+ data.state = function () {
550
+ if (this.jqXHR) {
551
+ return that._getDeferredState(this.jqXHR);
552
+ }
553
+ };
554
+ data.progress = function () {
555
+ return this._progress;
556
+ };
557
+ },
558
+
525
559
  // Parses the Range header from the server response
526
560
  // and returns the uploaded bytes:
527
561
  _getUploadedBytes: function (jqXHR) {
@@ -566,7 +600,8 @@
566
600
  // The chunk upload method:
567
601
  upload = function () {
568
602
  // Clone the options object for each chunk upload:
569
- var o = $.extend({}, options);
603
+ var o = $.extend({}, options),
604
+ currentLoaded = o._progress.loaded;
570
605
  o.blob = slice.call(
571
606
  file,
572
607
  ub,
@@ -588,10 +623,10 @@
588
623
  .done(function (result, textStatus, jqXHR) {
589
624
  ub = that._getUploadedBytes(jqXHR) ||
590
625
  (ub + o.chunkSize);
591
- // Create a progress event if upload is done and no progress
592
- // event has been invoked for this chunk, or there has been
593
- // no progress event with loaded equaling total:
594
- if (!o.loaded || o.loaded < o.total) {
626
+ // Create a progress event if no final progress event
627
+ // with loaded equaling total has been triggered
628
+ // for this chunk:
629
+ if (o._progress.loaded === currentLoaded) {
595
630
  that._onProgress($.Event('progress', {
596
631
  lengthComputable: true,
597
632
  loaded: ub - o.uploadedBytes,
@@ -643,20 +678,27 @@
643
678
  this._trigger('start');
644
679
  // Set timer for global bitrate progress calculation:
645
680
  this._bitrateTimer = new this._BitrateTimer();
681
+ // Reset the global progress values:
682
+ this._progress.loaded = this._progress.total = 0;
683
+ this._progress.bitrate = 0;
646
684
  }
685
+ if (!data._progress) {
686
+ data._progress = {};
687
+ }
688
+ data._progress.loaded = data.loaded = data.uploadedBytes || 0;
689
+ data._progress.total = data.total = this._getTotal(data.files) || 1;
690
+ data._progress.bitrate = data.bitrate = 0;
647
691
  this._active += 1;
648
692
  // Initialize the global progress values:
649
- this._loaded += data.uploadedBytes || 0;
650
- this._total += this._getTotal(data.files);
693
+ this._progress.loaded += data.loaded;
694
+ this._progress.total += data.total;
651
695
  },
652
696
 
653
697
  _onDone: function (result, textStatus, jqXHR, options) {
654
- if (!this._isXHRUpload(options) || !options.loaded ||
655
- options.loaded < options.total) {
656
- var total = this._getTotal(options.files) || 1;
657
- // Create a progress event for each iframe load,
658
- // or if there has been no progress event with
659
- // loaded equaling total for XHR uploads:
698
+ var total = options._progress.total;
699
+ if (options._progress.loaded < total) {
700
+ // Create a progress event if no final progress event
701
+ // with loaded equaling total has been triggered:
660
702
  this._onProgress($.Event('progress', {
661
703
  lengthComputable: true,
662
704
  loaded: total,
@@ -677,8 +719,8 @@
677
719
  if (options.recalculateProgress) {
678
720
  // Remove the failed (error or abort) file upload from
679
721
  // the global progress calculation:
680
- this._loaded -= options.loaded || options.uploadedBytes || 0;
681
- this._total -= options.total || this._getTotal(options.files);
722
+ this._progress.loaded -= options._progress.loaded;
723
+ this._progress.total -= options._progress.total;
682
724
  }
683
725
  },
684
726
 
@@ -691,13 +733,13 @@
691
733
  // The stop callback is triggered when all uploads have
692
734
  // been completed, equivalent to the global ajaxStop event:
693
735
  this._trigger('stop');
694
- // Reset the global progress values:
695
- this._loaded = this._total = 0;
696
- this._bitrateTimer = null;
697
736
  }
698
737
  },
699
738
 
700
739
  _onSend: function (e, data) {
740
+ if (!data.submit) {
741
+ this._addConvenienceMethods(e, data);
742
+ }
701
743
  var that = this,
702
744
  jqXHR,
703
745
  aborted,
@@ -728,15 +770,9 @@
728
770
  options.limitConcurrentUploads > that._sending) {
729
771
  // Start the next queued upload,
730
772
  // that has not been aborted:
731
- var nextSlot = that._slots.shift(),
732
- isPending;
773
+ var nextSlot = that._slots.shift();
733
774
  while (nextSlot) {
734
- // jQuery 1.6 doesn't provide .state(),
735
- // while jQuery 1.8+ removed .isRejected():
736
- isPending = nextSlot.state ?
737
- nextSlot.state() === 'pending' :
738
- !nextSlot.isRejected();
739
- if (isPending) {
775
+ if (that._getDeferredState(nextSlot) === 'pending') {
740
776
  nextSlot.resolve();
741
777
  break;
742
778
  }
@@ -808,12 +844,8 @@
808
844
  var newData = $.extend({}, data);
809
845
  newData.files = fileSet ? element : [element];
810
846
  newData.paramName = paramNameSet[index];
811
- newData.submit = function () {
812
- newData.jqXHR = this.jqXHR =
813
- (that._trigger('submit', e, this) !== false) &&
814
- that._onSend(e, this);
815
- return this.jqXHR;
816
- };
847
+ that._initProgressObject(newData);
848
+ that._addConvenienceMethods(e, newData);
817
849
  result = that._trigger('add', e, newData);
818
850
  return result;
819
851
  });
@@ -1087,12 +1119,17 @@
1087
1119
  this._initSpecialOptions();
1088
1120
  this._slots = [];
1089
1121
  this._sequence = this._getXHRPromise(true);
1090
- this._sending = this._active = this._loaded = this._total = 0;
1122
+ this._sending = this._active = 0;
1123
+ this._initProgressObject(this);
1091
1124
  this._initEventHandlers();
1092
1125
  },
1093
1126
 
1094
- _destroy: function () {
1095
- this._destroyEventHandlers();
1127
+ // This method is exposed to the widget API and allows to query
1128
+ // the widget upload progress.
1129
+ // It returns an object with loaded, total and bitrate properties
1130
+ // for the running uploads:
1131
+ progress: function () {
1132
+ return this._progress;
1096
1133
  },
1097
1134
 
1098
1135
  // This method is exposed to the widget API and allows adding files
metadata CHANGED
@@ -1,48 +1,48 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jquery.fileupload-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
5
4
  prerelease:
5
+ version: 1.3.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Semyon Perepelitsa
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-02 00:00:00.000000000 Z
12
+ date: 2013-03-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: railties
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
15
+ version_requirements: !ruby/object:Gem::Requirement
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '3.1'
20
+ none: false
21
+ name: railties
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
24
+ requirement: !ruby/object:Gem::Requirement
26
25
  requirements:
27
26
  - - ! '>='
28
27
  - !ruby/object:Gem::Version
29
28
  version: '3.1'
30
- - !ruby/object:Gem::Dependency
31
- name: jquery-ui-rails
32
- requirement: !ruby/object:Gem::Requirement
33
29
  none: false
30
+ - !ruby/object:Gem::Dependency
31
+ version_requirements: !ruby/object:Gem::Requirement
34
32
  requirements:
35
33
  - - ~>
36
34
  - !ruby/object:Gem::Version
37
35
  version: '3.0'
36
+ none: false
37
+ name: jquery-ui-rails
38
38
  type: :runtime
39
39
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
40
+ requirement: !ruby/object:Gem::Requirement
42
41
  requirements:
43
42
  - - ~>
44
43
  - !ruby/object:Gem::Version
45
44
  version: '3.0'
45
+ none: false
46
46
  description: This gem packages jQuery File Upload plugin and it's dependencies for
47
47
  Rails asset pipeline.
48
48
  email: sema@sema.in
@@ -90,20 +90,20 @@ rdoc_options: []
90
90
  require_paths:
91
91
  - lib
92
92
  required_ruby_version: !ruby/object:Gem::Requirement
93
- none: false
94
93
  requirements:
95
94
  - - ! '>='
96
95
  - !ruby/object:Gem::Version
97
96
  version: '0'
98
- required_rubygems_version: !ruby/object:Gem::Requirement
99
97
  none: false
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
99
  requirements:
101
100
  - - ! '>='
102
101
  - !ruby/object:Gem::Version
103
102
  version: '0'
103
+ none: false
104
104
  requirements: []
105
105
  rubyforge_project:
106
- rubygems_version: 1.8.24
106
+ rubygems_version: 1.8.23
107
107
  signing_key:
108
108
  specification_version: 3
109
109
  summary: Use jQuery File Upload plugin with Rails 3