Skip to content

Commit e3d1258

Browse files
author
Lars Mueller
committed
Updating to latest jquery fileupload version
1 parent 4425d7c commit e3d1258

File tree

7 files changed

+253
-119
lines changed

7 files changed

+253
-119
lines changed

vendor/assets/javascripts/jquery-fileupload/cors/jquery.postmessage-transport.js

100644100755
File mode changed.

vendor/assets/javascripts/jquery-fileupload/cors/jquery.xdr-transport.js

100644100755
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery XDomainRequest Transport Plugin 1.1.2
2+
* jQuery XDomainRequest Transport Plugin 1.1.3
33
* https://github.com/blueimp/jQuery-File-Upload
44
*
55
* Copyright 2011, Sebastian Tschan
@@ -36,6 +36,7 @@
3636
var xdr;
3737
return {
3838
send: function (headers, completeCallback) {
39+
var addParamChar = /\?/.test(s.url) ? '&' : '?';
3940
function callback(status, statusText, responses, responseHeaders) {
4041
xdr.onload = xdr.onerror = xdr.ontimeout = $.noop;
4142
xdr = null;
@@ -44,12 +45,13 @@
4445
xdr = new XDomainRequest();
4546
// XDomainRequest only supports GET and POST:
4647
if (s.type === 'DELETE') {
47-
s.url = s.url + (/\?/.test(s.url) ? '&' : '?') +
48-
'_method=DELETE';
48+
s.url = s.url + addParamChar + '_method=DELETE';
4949
s.type = 'POST';
5050
} else if (s.type === 'PUT') {
51-
s.url = s.url + (/\?/.test(s.url) ? '&' : '?') +
52-
'_method=PUT';
51+
s.url = s.url + addParamChar + '_method=PUT';
52+
s.type = 'POST';
53+
} else if (s.type === 'PATCH') {
54+
s.url = s.url + addParamChar + '_method=PATCH';
5355
s.type = 'POST';
5456
}
5557
xdr.open(s.type, s.url);

vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-fp.js

100644100755
File mode changed.

vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-ui.js

100644100755
Lines changed: 92 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery File Upload User Interface Plugin 6.11
2+
* jQuery File Upload User Interface Plugin 7.3
33
* https://github.com/blueimp/jQuery-File-Upload
44
*
55
* Copyright 2010, Sebastian Tschan
@@ -83,7 +83,8 @@
8383
// widget (via file input selection, drag & drop or add API call).
8484
// See the basic file upload widget for more information:
8585
add: function (e, data) {
86-
var that = $(this).data('fileupload'),
86+
var that = $(this).data('blueimp-fileupload') ||
87+
$(this).data('fileupload'),
8788
options = that.options,
8889
files = data.files;
8990
$(this).fileupload('process', data).done(function () {
@@ -94,7 +95,7 @@
9495
options.filesContainer[
9596
options.prependFiles ? 'prepend' : 'append'
9697
](data.context);
97-
that._renderPreviews(files, data.context);
98+
that._renderPreviews(data);
9899
that._forceReflow(data.context);
99100
that._transition(data.context).done(
100101
function () {
@@ -109,7 +110,8 @@
109110
},
110111
// Callback for the start of each file upload request:
111112
send: function (e, data) {
112-
var that = $(this).data('fileupload');
113+
var that = $(this).data('blueimp-fileupload') ||
114+
$(this).data('fileupload');
113115
if (!data.isValidated) {
114116
if (!data.maxNumberOfFilesAdjusted) {
115117
that._adjustMaxNumberOfFiles(-data.files.length);
@@ -138,13 +140,16 @@
138140
},
139141
// Callback for successful uploads:
140142
done: function (e, data) {
141-
var that = $(this).data('fileupload'),
142-
template;
143+
var that = $(this).data('blueimp-fileupload') ||
144+
$(this).data('fileupload'),
145+
files = that._getFilesFromResponse(data),
146+
template,
147+
deferred;
143148
if (data.context) {
144149
data.context.each(function (index) {
145-
var file = ($.isArray(data.result) &&
146-
data.result[index]) ||
147-
{error: 'Empty file upload result'};
150+
var file = files[index] ||
151+
{error: 'Empty file upload result'},
152+
deferred = that._addFinishedDeferreds();
148153
if (file.error) {
149154
that._adjustMaxNumberOfFiles(1);
150155
}
@@ -158,14 +163,16 @@
158163
function () {
159164
data.context = $(this);
160165
that._trigger('completed', e, data);
166+
that._trigger('finished', e, data);
167+
deferred.resolve();
161168
}
162169
);
163170
}
164171
);
165172
});
166173
} else {
167-
if ($.isArray(data.result)) {
168-
$.each(data.result, function (index, file) {
174+
if (files.length) {
175+
$.each(files, function (index, file) {
169176
if (data.maxNumberOfFilesAdjusted && file.error) {
170177
that._adjustMaxNumberOfFiles(1);
171178
} else if (!data.maxNumberOfFilesAdjusted &&
@@ -175,21 +182,26 @@
175182
});
176183
data.maxNumberOfFilesAdjusted = true;
177184
}
178-
template = that._renderDownload(data.result)
185+
template = that._renderDownload(files)
179186
.appendTo(that.options.filesContainer);
180187
that._forceReflow(template);
188+
deferred = that._addFinishedDeferreds();
181189
that._transition(template).done(
182190
function () {
183191
data.context = $(this);
184192
that._trigger('completed', e, data);
193+
that._trigger('finished', e, data);
194+
deferred.resolve();
185195
}
186196
);
187197
}
188198
},
189199
// Callback for failed (abort or error) uploads:
190200
fail: function (e, data) {
191-
var that = $(this).data('fileupload'),
192-
template;
201+
var that = $(this).data('blueimp-fileupload') ||
202+
$(this).data('fileupload'),
203+
template,
204+
deferred;
193205
if (data.maxNumberOfFilesAdjusted) {
194206
that._adjustMaxNumberOfFiles(data.files.length);
195207
}
@@ -199,6 +211,7 @@
199211
var file = data.files[index];
200212
file.error = file.error || data.errorThrown ||
201213
true;
214+
deferred = that._addFinishedDeferreds();
202215
that._transition($(this)).done(
203216
function () {
204217
var node = $(this);
@@ -209,15 +222,20 @@
209222
function () {
210223
data.context = $(this);
211224
that._trigger('failed', e, data);
225+
that._trigger('finished', e, data);
226+
deferred.resolve();
212227
}
213228
);
214229
}
215230
);
216231
} else {
232+
deferred = that._addFinishedDeferreds();
217233
that._transition($(this)).done(
218234
function () {
219235
$(this).remove();
220236
that._trigger('failed', e, data);
237+
that._trigger('finished', e, data);
238+
deferred.resolve();
221239
}
222240
);
223241
}
@@ -227,14 +245,19 @@
227245
.appendTo(that.options.filesContainer)
228246
.data('data', data);
229247
that._forceReflow(data.context);
248+
deferred = that._addFinishedDeferreds();
230249
that._transition(data.context).done(
231250
function () {
232251
data.context = $(this);
233252
that._trigger('failed', e, data);
253+
that._trigger('finished', e, data);
254+
deferred.resolve();
234255
}
235256
);
236257
} else {
237258
that._trigger('failed', e, data);
259+
that._trigger('finished', e, data);
260+
that._addFinishedDeferreds().resolve();
238261
}
239262
},
240263
// Callback for upload progress events:
@@ -258,7 +281,8 @@
258281
.find('.progress-extended');
259282
if (extendedProgressNode.length) {
260283
extendedProgressNode.html(
261-
$this.data('fileupload')._renderExtendedProgress(data)
284+
($this.data('blueimp-fileupload') || $this.data('fileupload'))
285+
._renderExtendedProgress(data)
262286
);
263287
}
264288
globalProgressNode
@@ -271,7 +295,9 @@
271295
},
272296
// Callback for uploads start, equivalent to the global ajaxStart event:
273297
start: function (e) {
274-
var that = $(this).data('fileupload');
298+
var that = $(this).data('blueimp-fileupload') ||
299+
$(this).data('fileupload');
300+
that._resetFinishedDeferreds();
275301
that._transition($(this).find('.fileupload-progress')).done(
276302
function () {
277303
that._trigger('started', e);
@@ -280,20 +306,27 @@
280306
},
281307
// Callback for uploads stop, equivalent to the global ajaxStop event:
282308
stop: function (e) {
283-
var that = $(this).data('fileupload');
309+
var that = $(this).data('blueimp-fileupload') ||
310+
$(this).data('fileupload'),
311+
deferred = that._addFinishedDeferreds();
312+
$.when.apply($, that._getFinishedDeferreds())
313+
.done(function () {
314+
that._trigger('stopped', e);
315+
});
284316
that._transition($(this).find('.fileupload-progress')).done(
285317
function () {
286318
$(this).find('.progress')
287319
.attr('aria-valuenow', '0')
288320
.find('.bar').css('width', '0%');
289321
$(this).find('.progress-extended').html(' ');
290-
that._trigger('stopped', e);
322+
deferred.resolve();
291323
}
292324
);
293325
},
294326
// Callback for file deletion:
295327
destroy: function (e, data) {
296-
var that = $(this).data('fileupload');
328+
var that = $(this).data('blueimp-fileupload') ||
329+
$(this).data('fileupload');
297330
if (data.url) {
298331
$.ajax(data);
299332
that._adjustMaxNumberOfFiles(1);
@@ -307,6 +340,29 @@
307340
}
308341
},
309342

343+
_resetFinishedDeferreds: function () {
344+
this._finishedUploads = [];
345+
},
346+
347+
_addFinishedDeferreds: function (deferred) {
348+
if (!deferred) {
349+
deferred = $.Deferred();
350+
}
351+
this._finishedUploads.push(deferred);
352+
return deferred;
353+
},
354+
355+
_getFinishedDeferreds: function () {
356+
return this._finishedUploads;
357+
},
358+
359+
_getFilesFromResponse: function (data) {
360+
if (data.result && $.isArray(data.result.files)) {
361+
return data.result.files;
362+
}
363+
return [];
364+
},
365+
310366
// Link handler, that allows to download files
311367
// by drag & drop of the links to the desktop:
312368
_enableDragToDesktop: function () {
@@ -361,7 +417,7 @@
361417
if (bits >= 1000) {
362418
return (bits / 1000).toFixed(2) + ' kbit/s';
363419
}
364-
return bits + ' bit/s';
420+
return bits.toFixed(2) + ' bit/s';
365421
},
366422

367423
_formatTime: function (seconds) {
@@ -472,18 +528,22 @@
472528
)) || dfd.resolveWith(node)) && dfd;
473529
},
474530

475-
_renderPreviews: function (files, nodes) {
531+
_renderPreviews: function (data) {
476532
var that = this,
477533
options = this.options;
478-
nodes.find('.preview span').each(function (index, element) {
479-
var file = files[index];
534+
data.context.find('.preview span').each(function (index, element) {
535+
var file = data.files[index];
480536
if (options.previewSourceFileTypes.test(file.type) &&
481537
($.type(options.previewSourceMaxFileSize) !== 'number' ||
482538
file.size < options.previewSourceMaxFileSize)) {
483539
that._processingQueue = that._processingQueue.pipe(function () {
484-
var dfd = $.Deferred();
540+
var dfd = $.Deferred(),
541+
ev = $.Event('previewdone', {
542+
target: element
543+
});
485544
that._renderPreview(file, $(element)).done(
486545
function () {
546+
that._trigger(ev.type, ev, data);
487547
dfd.resolveWith(that);
488548
}
489549
);
@@ -691,6 +751,13 @@
691751
this._initRegExpOptions();
692752
},
693753

754+
_setOption: function (key, value) {
755+
this._super(key, value);
756+
if (key === 'maxNumberOfFiles') {
757+
this._adjustMaxNumberOfFiles(0);
758+
}
759+
},
760+
694761
_create: function () {
695762
this._super();
696763
this._refreshOptionsList.push(
@@ -704,6 +771,7 @@
704771
return this._processingQueue;
705772
};
706773
}
774+
this._resetFinishedDeferreds();
707775
},
708776

709777
enable: function () {

0 commit comments

Comments
 (0)