Skip to content

Commit 70a41e9

Browse files
committed
Make sure the submit and abort convenience methods always return a jqXHR object.
1 parent 5c2934a commit 70a41e9

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

js/jquery.fileupload.js

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,30 @@
520520
return this._enhancePromise(promise);
521521
},
522522

523+
// Adds convenience methods to the callback arguments:
524+
_addConvenienceMethods: function (e, data) {
525+
var that = this;
526+
data.submit = function () {
527+
if (this.state() !== 'pending') {
528+
data.jqXHR = this.jqXHR =
529+
(that._trigger('submit', e, this) !== false) &&
530+
that._onSend(e, this);
531+
}
532+
return this.jqXHR || that._getXHRPromise();
533+
};
534+
data.abort = function () {
535+
if (this.jqXHR) {
536+
return this.jqXHR.abort();
537+
}
538+
return this._getXHRPromise();
539+
};
540+
data.state = function () {
541+
if (this.jqXHR) {
542+
return that._getDeferredState(this.jqXHR);
543+
}
544+
};
545+
},
546+
523547
// Parses the Range header from the server response
524548
// and returns the uploaded bytes:
525549
_getUploadedBytes: function (jqXHR) {
@@ -802,25 +826,7 @@
802826
var newData = $.extend({}, data);
803827
newData.files = fileSet ? element : [element];
804828
newData.paramName = paramNameSet[index];
805-
newData.submit = function () {
806-
if (this.state() === 'pending') {
807-
return this.jqXHR;
808-
}
809-
newData.jqXHR = this.jqXHR =
810-
(that._trigger('submit', e, this) !== false) &&
811-
that._onSend(e, this);
812-
return this.jqXHR;
813-
};
814-
newData.abort = function () {
815-
if (this.jqXHR) {
816-
return this.jqXHR.abort();
817-
}
818-
};
819-
newData.state = function () {
820-
if (this.jqXHR) {
821-
return that._getDeferredState(this.jqXHR);
822-
}
823-
};
829+
that._addConvenienceMethods(e, newData);
824830
result = that._trigger('add', e, newData);
825831
return result;
826832
});

0 commit comments

Comments
 (0)