|
520 | 520 | return this._enhancePromise(promise);
|
521 | 521 | },
|
522 | 522 |
|
| 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 | + |
523 | 547 | // Parses the Range header from the server response
|
524 | 548 | // and returns the uploaded bytes:
|
525 | 549 | _getUploadedBytes: function (jqXHR) {
|
|
802 | 826 | var newData = $.extend({}, data);
|
803 | 827 | newData.files = fileSet ? element : [element];
|
804 | 828 | 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); |
824 | 830 | result = that._trigger('add', e, newData);
|
825 | 831 | return result;
|
826 | 832 | });
|
|
0 commit comments