Skip to content

Commit 52f79b6

Browse files
committed
Update jQuery File Upload User Interface Plugin to 9.5.2
1 parent be7ff92 commit 52f79b6

File tree

1 file changed

+114
-48
lines changed

1 file changed

+114
-48
lines changed

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

Lines changed: 114 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery File Upload User Interface Plugin 8.2.1
2+
* jQuery File Upload User Interface Plugin 9.5.2
33
* https://github.com/blueimp/jQuery-File-Upload
44
*
55
* Copyright 2010, Sebastian Tschan
@@ -9,8 +9,8 @@
99
* http://www.opensource.org/licenses/MIT
1010
*/
1111

12-
/*jslint nomen: true, unparam: true, regexp: true */
13-
/*global define, window, URL, webkitURL, FileReader */
12+
/* jshint nomen:false */
13+
/* global define, window */
1414

1515
(function (factory) {
1616
'use strict';
@@ -19,7 +19,9 @@
1919
define([
2020
'jquery',
2121
'tmpl',
22-
'./jquery.fileupload-resize',
22+
'./jquery.fileupload-image',
23+
'./jquery.fileupload-audio',
24+
'./jquery.fileupload-video',
2325
'./jquery.fileupload-validate'
2426
], factory);
2527
} else {
@@ -29,7 +31,7 @@
2931
window.tmpl
3032
);
3133
}
32-
}(function ($, tmpl, loadImage) {
34+
}(function ($, tmpl) {
3335
'use strict';
3436

3537
$.blueimp.fileupload.prototype._specialOptions.push(
@@ -64,7 +66,8 @@
6466
// Function returning the current number of files,
6567
// used by the maxNumberOfFiles validation:
6668
getNumberOfFiles: function () {
67-
return this.filesContainer.children().length;
69+
return this.filesContainer.children()
70+
.not('.processing').length;
6871
},
6972

7073
// Callback to retrieve the list of files from the server response:
@@ -79,33 +82,53 @@
7982
// widget (via file input selection, drag & drop or add API call).
8083
// See the basic file upload widget for more information:
8184
add: function (e, data) {
85+
if (e.isDefaultPrevented()) {
86+
return false;
87+
}
8288
var $this = $(this),
8389
that = $this.data('blueimp-fileupload') ||
8490
$this.data('fileupload'),
85-
options = that.options,
86-
files = data.files;
91+
options = that.options;
92+
data.context = that._renderUpload(data.files)
93+
.data('data', data)
94+
.addClass('processing');
95+
options.filesContainer[
96+
options.prependFiles ? 'prepend' : 'append'
97+
](data.context);
98+
that._forceReflow(data.context);
99+
that._transition(data.context);
87100
data.process(function () {
88101
return $this.fileupload('process', data);
89102
}).always(function () {
90-
data.context = that._renderUpload(files).data('data', data);
103+
data.context.each(function (index) {
104+
$(this).find('.size').text(
105+
that._formatFileSize(data.files[index].size)
106+
);
107+
}).removeClass('processing');
91108
that._renderPreviews(data);
92-
options.filesContainer[
93-
options.prependFiles ? 'prepend' : 'append'
94-
](data.context);
95-
that._forceReflow(data.context);
96-
that._transition(data.context).done(
97-
function () {
98-
if ((that._trigger('added', e, data) !== false) &&
99-
(options.autoUpload || data.autoUpload) &&
100-
data.autoUpload !== false && !data.files.error) {
101-
data.submit();
109+
}).done(function () {
110+
data.context.find('.start').prop('disabled', false);
111+
if ((that._trigger('added', e, data) !== false) &&
112+
(options.autoUpload || data.autoUpload) &&
113+
data.autoUpload !== false) {
114+
data.submit();
115+
}
116+
}).fail(function () {
117+
if (data.files.error) {
118+
data.context.each(function (index) {
119+
var error = data.files[index].error;
120+
if (error) {
121+
$(this).find('.error').text(error);
102122
}
103-
}
104-
);
123+
});
124+
}
105125
});
106126
},
107127
// Callback for the start of each file upload request:
108128
send: function (e, data) {
129+
if (e.isDefaultPrevented()) {
130+
return false;
131+
}
109132
var that = $(this).data('blueimp-fileupload') ||
110133
$(this).data('fileupload');
111134
if (data.context && data.dataType &&
@@ -118,7 +141,7 @@
118141
!$.support.transition && 'progress-animated'
119142
)
120143
.attr('aria-valuenow', 100)
121-
.find('.bar').css(
144+
.children().first().css(
122145
'width',
123146
'100%'
124147
);
@@ -127,6 +150,9 @@
127150
},
128151
// Callback for successful uploads:
129152
done: function (e, data) {
153+
if (e.isDefaultPrevented()) {
154+
return false;
155+
}
130156
var that = $(this).data('blueimp-fileupload') ||
131157
$(this).data('fileupload'),
132158
getFilesFromResponse = data.getFilesFromResponse ||
@@ -137,8 +163,8 @@
137163
if (data.context) {
138164
data.context.each(function (index) {
139165
var file = files[index] ||
140-
{error: 'Empty file upload result'},
141-
deferred = that._addFinishedDeferreds();
166+
{error: 'Empty file upload result'};
167+
deferred = that._addFinishedDeferreds();
142168
that._transition($(this)).done(
143169
function () {
144170
var node = $(this);
@@ -157,8 +183,9 @@
157183
);
158184
});
159185
} else {
160-
template = that._renderDownload(files)
161-
.appendTo(that.options.filesContainer);
186+
template = that._renderDownload(files)[
187+
that.options.prependFiles ? 'prependTo' : 'appendTo'
188+
](that.options.filesContainer);
162189
that._forceReflow(template);
163190
deferred = that._addFinishedDeferreds();
164191
that._transition(template).done(
@@ -173,6 +200,9 @@
173200
},
174201
// Callback for failed (abort or error) uploads:
175202
fail: function (e, data) {
203+
if (e.isDefaultPrevented()) {
204+
return false;
205+
}
176206
var that = $(this).data('blueimp-fileupload') ||
177207
$(this).data('fileupload'),
178208
template,
@@ -213,8 +243,9 @@
213243
}
214244
});
215245
} else if (data.errorThrown !== 'abort') {
216-
data.context = that._renderUpload(data.files)
217-
.appendTo(that.options.filesContainer)
246+
data.context = that._renderUpload(data.files)[
247+
that.options.prependFiles ? 'prependTo' : 'appendTo'
248+
](that.options.filesContainer)
218249
.data('data', data);
219250
that._forceReflow(data.context);
220251
deferred = that._addFinishedDeferreds();
@@ -234,18 +265,26 @@
234265
},
235266
// Callback for upload progress events:
236267
progress: function (e, data) {
268+
if (e.isDefaultPrevented()) {
269+
return false;
270+
}
271+
var progress = Math.floor(data.loaded / data.total * 100);
237272
if (data.context) {
238-
var progress = Math.floor(data.loaded / data.total * 100);
239-
data.context.find('.progress')
240-
.attr('aria-valuenow', progress)
241-
.find('.bar').css(
242-
'width',
243-
progress + '%'
244-
);
273+
data.context.each(function () {
274+
$(this).find('.progress')
275+
.attr('aria-valuenow', progress)
276+
.children().first().css(
277+
'width',
278+
progress + '%'
279+
);
280+
});
245281
}
246282
},
247283
// Callback for global upload progress events:
248284
progressall: function (e, data) {
285+
if (e.isDefaultPrevented()) {
286+
return false;
287+
}
249288
var $this = $(this),
250289
progress = Math.floor(data.loaded / data.total * 100),
251290
globalProgressNode = $this.find('.fileupload-progress'),
@@ -260,13 +299,16 @@
260299
globalProgressNode
261300
.find('.progress')
262301
.attr('aria-valuenow', progress)
263-
.find('.bar').css(
302+
.children().first().css(
264303
'width',
265304
progress + '%'
266305
);
267306
},
268307
// Callback for uploads start, equivalent to the global ajaxStart event:
269308
start: function (e) {
309+
if (e.isDefaultPrevented()) {
310+
return false;
311+
}
270312
var that = $(this).data('blueimp-fileupload') ||
271313
$(this).data('fileupload');
272314
that._resetFinishedDeferreds();
@@ -278,6 +320,9 @@
278320
},
279321
// Callback for uploads stop, equivalent to the global ajaxStop event:
280322
stop: function (e) {
323+
if (e.isDefaultPrevented()) {
324+
return false;
325+
}
281326
var that = $(this).data('blueimp-fileupload') ||
282327
$(this).data('fileupload'),
283328
deferred = that._addFinishedDeferreds();
@@ -289,31 +334,46 @@
289334
function () {
290335
$(this).find('.progress')
291336
.attr('aria-valuenow', '0')
292-
.find('.bar').css('width', '0%');
337+
.children().first().css('width', '0%');
293338
$(this).find('.progress-extended').html(' ');
294339
deferred.resolve();
295340
}
296341
);
297342
},
298-
processstart: function () {
343+
processstart: function (e) {
344+
if (e.isDefaultPrevented()) {
345+
return false;
346+
}
299347
$(this).addClass('fileupload-processing');
300348
},
301-
processstop: function () {
349+
processstop: function (e) {
350+
if (e.isDefaultPrevented()) {
351+
return false;
352+
}
302353
$(this).removeClass('fileupload-processing');
303354
},
304355
// Callback for file deletion:
305356
destroy: function (e, data) {
357+
if (e.isDefaultPrevented()) {
358+
return false;
359+
}
306360
var that = $(this).data('blueimp-fileupload') ||
307-
$(this).data('fileupload');
308-
if (data.url) {
309-
$.ajax(data).done(function () {
361+
$(this).data('fileupload'),
362+
removeNode = function () {
310363
that._transition(data.context).done(
311364
function () {
312365
$(this).remove();
313366
that._trigger('destroyed', e, data);
314367
}
315368
);
369+
};
370+
if (data.url) {
371+
data.dataType = data.dataType || that.options.dataType;
372+
$.ajax(data).done(removeNode).fail(function () {
373+
that._trigger('destroyfailed', e, data);
316374
});
375+
} else {
376+
removeNode();
317377
}
318378
}
319379
},
@@ -446,20 +506,23 @@
446506
var button = $(e.currentTarget),
447507
template = button.closest('.template-upload'),
448508
data = template.data('data');
449-
if (data && data.submit && !data.jqXHR && data.submit()) {
450-
button.prop('disabled', true);
509+
button.prop('disabled', true);
510+
if (data && data.submit) {
511+
data.submit();
451512
}
452513
},
453514

454515
_cancelHandler: function (e) {
455516
e.preventDefault();
456-
var template = $(e.currentTarget).closest('.template-upload'),
517+
var template = $(e.currentTarget)
518+
.closest('.template-upload,.template-download'),
457519
data = template.data('data') || {};
458-
if (!data.jqXHR) {
520+
data.context = data.context || template;
521+
if (data.abort) {
522+
data.abort();
523+
} else {
459524
data.errorThrown = 'abort';
460525
this._trigger('fail', e, data);
461-
} else {
462-
data.jqXHR.abort();
463526
}
464527
},
465528

@@ -606,6 +669,9 @@
606669
_create: function () {
607670
this._super();
608671
this._resetFinishedDeferreds();
672+
if (!$.support.fileInput) {
673+
this._disableFileInputButton();
674+
}
609675
},
610676

611677
enable: function () {

0 commit comments

Comments
 (0)