|
1 | 1 | /* |
2 | | - * jQuery File Upload Plugin 5.19.8 |
| 2 | + * jQuery File Upload Plugin 5.20 |
3 | 3 | * https://github.com/blueimp/jQuery-File-Upload |
4 | 4 | * |
5 | 5 | * Copyright 2010, Sebastian Tschan |
|
140 | 140 | }, |
141 | 141 |
|
142 | 142 | // Other callbacks: |
| 143 | + |
143 | 144 | // Callback for the submit event of each file upload: |
144 | 145 | // submit: function (e, data) {}, // .bind('fileuploadsubmit', func); |
| 146 | + |
145 | 147 | // Callback for the start of each file upload request: |
146 | 148 | // send: function (e, data) {}, // .bind('fileuploadsend', func); |
| 149 | + |
147 | 150 | // Callback for successful uploads: |
148 | 151 | // done: function (e, data) {}, // .bind('fileuploaddone', func); |
| 152 | + |
149 | 153 | // Callback for failed (abort or error) uploads: |
150 | 154 | // fail: function (e, data) {}, // .bind('fileuploadfail', func); |
| 155 | + |
151 | 156 | // Callback for completed (success, abort or error) requests: |
152 | 157 | // always: function (e, data) {}, // .bind('fileuploadalways', func); |
| 158 | + |
153 | 159 | // Callback for upload progress events: |
154 | 160 | // progress: function (e, data) {}, // .bind('fileuploadprogress', func); |
| 161 | + |
155 | 162 | // Callback for global upload progress events: |
156 | 163 | // progressall: function (e, data) {}, // .bind('fileuploadprogressall', func); |
| 164 | + |
157 | 165 | // Callback for uploads start, equivalent to the global ajaxStart event: |
158 | 166 | // start: function (e) {}, // .bind('fileuploadstart', func); |
| 167 | + |
159 | 168 | // Callback for uploads stop, equivalent to the global ajaxStop event: |
160 | 169 | // stop: function (e) {}, // .bind('fileuploadstop', func); |
| 170 | + |
161 | 171 | // Callback for change events of the fileInput(s): |
162 | 172 | // change: function (e, data) {}, // .bind('fileuploadchange', func); |
| 173 | + |
163 | 174 | // Callback for paste events to the pasteZone(s): |
164 | 175 | // paste: function (e, data) {}, // .bind('fileuploadpaste', func); |
| 176 | + |
165 | 177 | // Callback for drop events of the dropZone(s): |
166 | 178 | // drop: function (e, data) {}, // .bind('fileuploaddrop', func); |
| 179 | + |
167 | 180 | // Callback for dragover events of the dropZone(s): |
168 | 181 | // dragover: function (e) {}, // .bind('fileuploaddragover', func); |
169 | 182 |
|
| 183 | + // Callback for the start of each chunk upload request: |
| 184 | + // chunksend: function (e, data) {}, // .bind('fileuploadchunksend', func); |
| 185 | + |
| 186 | + // Callback for successful chunk uploads: |
| 187 | + // chunkdone: function (e, data) {}, // .bind('fileuploadchunkdone', func); |
| 188 | + |
| 189 | + // Callback for failed (abort or error) chunk uploads: |
| 190 | + // chunkfail: function (e, data) {}, // .bind('fileuploadchunkfail', func); |
| 191 | + |
| 192 | + // Callback for completed (success, abort or error) chunk upload requests: |
| 193 | + // chunkalways: function (e, data) {}, // .bind('fileuploadchunkalways', func); |
| 194 | + |
170 | 195 | // The plugin options are used as settings object for the ajax calls. |
171 | 196 | // The following are jQuery ajax settings required for the file uploads: |
172 | 197 | processData: false, |
|
540 | 565 | that._initXHRData(o); |
541 | 566 | // Add progress listeners for this chunk upload: |
542 | 567 | that._initProgressListener(o); |
543 | | - jqXHR = ($.ajax(o) || that._getXHRPromise(false, o.context)) |
| 568 | + jqXHR = ((that._trigger('chunksend', null, o) !== false && $.ajax(o)) || |
| 569 | + that._getXHRPromise(false, o.context)) |
544 | 570 | .done(function (result, textStatus, jqXHR) { |
545 | 571 | ub = that._getUploadedBytes(jqXHR) || |
546 | 572 | (ub + o.chunkSize); |
|
554 | 580 | }), o); |
555 | 581 | } |
556 | 582 | options.uploadedBytes = o.uploadedBytes = ub; |
| 583 | + o.result = result; |
| 584 | + o.textStatus = textStatus; |
| 585 | + o.jqXHR = jqXHR; |
| 586 | + that._trigger('chunkdone', null, o); |
| 587 | + that._trigger('chunkalways', null, o); |
557 | 588 | if (ub < fs) { |
558 | 589 | // File upload not yet complete, |
559 | 590 | // continue with the next chunk: |
|
566 | 597 | } |
567 | 598 | }) |
568 | 599 | .fail(function (jqXHR, textStatus, errorThrown) { |
| 600 | + o.jqXHR = jqXHR; |
| 601 | + o.textStatus = textStatus; |
| 602 | + o.errorThrown = errorThrown; |
| 603 | + that._trigger('chunkfail', null, o); |
| 604 | + that._trigger('chunkalways', null, o); |
569 | 605 | dfd.rejectWith( |
570 | 606 | o.context, |
571 | 607 | [jqXHR, textStatus, errorThrown] |
|
624 | 660 | }, |
625 | 661 |
|
626 | 662 | _onAlways: function (jqXHRorResult, textStatus, jqXHRorError, options) { |
| 663 | + // jqXHRorResult, textStatus and jqXHRorError are added to the |
| 664 | + // options object via done and fail callbacks |
627 | 665 | this._active -= 1; |
628 | | - options.textStatus = textStatus; |
629 | | - if (jqXHRorError && jqXHRorError.always) { |
630 | | - options.jqXHR = jqXHRorError; |
631 | | - options.result = jqXHRorResult; |
632 | | - } else { |
633 | | - options.jqXHR = jqXHRorResult; |
634 | | - options.errorThrown = jqXHRorError; |
635 | | - } |
636 | 666 | this._trigger('always', null, options); |
637 | 667 | if (this._active === 0) { |
638 | 668 | // The stop callback is triggered when all uploads have |
|
0 commit comments