Skip to content

Commit c48370e

Browse files
committed
Reject the processing if the errorThrown property has been set.
This allows aborting the processing queue via data.abort() call.
1 parent 2c188af commit c48370e

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

js/jquery.fileupload-process.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery File Upload Processing Plugin 1.2.2
2+
* jQuery File Upload Processing Plugin 1.3.0
33
* https://github.com/blueimp/jQuery-File-Upload
44
*
55
* Copyright 2012, Sebastian Tschan
@@ -64,13 +64,17 @@
6464
*/
6565
},
6666

67-
_processFile: function (data) {
67+
_processFile: function (data, originalData) {
6868
var that = this,
6969
dfd = $.Deferred().resolveWith(that, [data]),
7070
chain = dfd.promise();
7171
this._trigger('process', null, data);
7272
$.each(data.processQueue, function (i, settings) {
7373
var func = function (data) {
74+
if (originalData.errorThrown) {
75+
return $.Deferred()
76+
.rejectWith(that, [originalData]).promise();
77+
}
7478
return that.processActions[settings.action].call(
7579
that,
7680
data,
@@ -136,7 +140,11 @@
136140
$.each(data.files, function (index) {
137141
var opts = index ? $.extend({}, options) : options,
138142
func = function () {
139-
return that._processFile(opts);
143+
if (data.errorThrown) {
144+
return $.Deferred()
145+
.rejectWith(that, [data]).promise();
146+
}
147+
return that._processFile(opts, data);
140148
};
141149
opts.index = index;
142150
that._processing += 1;

js/jquery.fileupload.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery File Upload Plugin 5.34.0
2+
* jQuery File Upload Plugin 5.35.0
33
* https://github.com/blueimp/jQuery-File-Upload
44
*
55
* Copyright 2010, Sebastian Tschan
@@ -607,16 +607,23 @@
607607
// Adds convenience methods to the data callback argument:
608608
_addConvenienceMethods: function (e, data) {
609609
var that = this,
610-
getPromise = function (data) {
611-
return $.Deferred().resolveWith(that, [data]).promise();
610+
getPromise = function (args) {
611+
return $.Deferred().resolveWith(that, args).promise();
612612
};
613613
data.process = function (resolveFunc, rejectFunc) {
614614
if (resolveFunc || rejectFunc) {
615615
data._processQueue = this._processQueue =
616-
(this._processQueue || getPromise(this))
617-
.pipe(resolveFunc, rejectFunc);
616+
(this._processQueue || getPromise([this])).pipe(
617+
function () {
618+
if (data.errorThrown) {
619+
return $.Deferred()
620+
.rejectWith(that, [data]).promise();
621+
}
622+
return getPromise(arguments);
623+
}
624+
).pipe(resolveFunc, rejectFunc);
618625
}
619-
return this._processQueue || getPromise(this);
626+
return this._processQueue || getPromise([this]);
620627
};
621628
data.submit = function () {
622629
if (this.state() !== 'pending') {
@@ -633,6 +640,7 @@
633640
if (this.jqXHR) {
634641
return this.jqXHR.abort();
635642
}
643+
this.errorThrown = 'abort';
636644
return that._getXHRPromise();
637645
};
638646
data.state = function () {

0 commit comments

Comments
 (0)