Skip to content
This repository was archived by the owner on May 25, 2023. It is now read-only.

Commit 1c0df67

Browse files
committed
Added callback triggers for chunk upload events.
// Callback for the start of each chunk upload request: chunksend: function (e, data) {}, // .bind('fileuploadchunksend', func); // Callback for successful chunk uploads: chunkdone: function (e, data) {}, // .bind('fileuploadchunkdone', func); // Callback for failed (abort or error) chunk uploads: chunkfail: function (e, data) {}, // .bind('fileuploadchunkfail', func); // Callback for completed (success, abort or error) chunk upload requests: chunkalways: function (e, data) {}, // .bind('fileuploadchunkalways', func);
1 parent 8f47665 commit 1c0df67

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

js/jquery.fileupload.js

+40-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery File Upload Plugin 5.19.8
2+
* jQuery File Upload Plugin 5.20
33
* https://github.com/blueimp/jQuery-File-Upload
44
*
55
* Copyright 2010, Sebastian Tschan
@@ -140,33 +140,58 @@
140140
},
141141

142142
// Other callbacks:
143+
143144
// Callback for the submit event of each file upload:
144145
// submit: function (e, data) {}, // .bind('fileuploadsubmit', func);
146+
145147
// Callback for the start of each file upload request:
146148
// send: function (e, data) {}, // .bind('fileuploadsend', func);
149+
147150
// Callback for successful uploads:
148151
// done: function (e, data) {}, // .bind('fileuploaddone', func);
152+
149153
// Callback for failed (abort or error) uploads:
150154
// fail: function (e, data) {}, // .bind('fileuploadfail', func);
155+
151156
// Callback for completed (success, abort or error) requests:
152157
// always: function (e, data) {}, // .bind('fileuploadalways', func);
158+
153159
// Callback for upload progress events:
154160
// progress: function (e, data) {}, // .bind('fileuploadprogress', func);
161+
155162
// Callback for global upload progress events:
156163
// progressall: function (e, data) {}, // .bind('fileuploadprogressall', func);
164+
157165
// Callback for uploads start, equivalent to the global ajaxStart event:
158166
// start: function (e) {}, // .bind('fileuploadstart', func);
167+
159168
// Callback for uploads stop, equivalent to the global ajaxStop event:
160169
// stop: function (e) {}, // .bind('fileuploadstop', func);
170+
161171
// Callback for change events of the fileInput(s):
162172
// change: function (e, data) {}, // .bind('fileuploadchange', func);
173+
163174
// Callback for paste events to the pasteZone(s):
164175
// paste: function (e, data) {}, // .bind('fileuploadpaste', func);
176+
165177
// Callback for drop events of the dropZone(s):
166178
// drop: function (e, data) {}, // .bind('fileuploaddrop', func);
179+
167180
// Callback for dragover events of the dropZone(s):
168181
// dragover: function (e) {}, // .bind('fileuploaddragover', func);
169182

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+
170195
// The plugin options are used as settings object for the ajax calls.
171196
// The following are jQuery ajax settings required for the file uploads:
172197
processData: false,
@@ -540,7 +565,8 @@
540565
that._initXHRData(o);
541566
// Add progress listeners for this chunk upload:
542567
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))
544570
.done(function (result, textStatus, jqXHR) {
545571
ub = that._getUploadedBytes(jqXHR) ||
546572
(ub + o.chunkSize);
@@ -554,6 +580,11 @@
554580
}), o);
555581
}
556582
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);
557588
if (ub < fs) {
558589
// File upload not yet complete,
559590
// continue with the next chunk:
@@ -566,6 +597,11 @@
566597
}
567598
})
568599
.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);
569605
dfd.rejectWith(
570606
o.context,
571607
[jqXHR, textStatus, errorThrown]
@@ -624,15 +660,9 @@
624660
},
625661

626662
_onAlways: function (jqXHRorResult, textStatus, jqXHRorError, options) {
663+
// jqXHRorResult, textStatus and jqXHRorError are added to the
664+
// options object via done and fail callbacks
627665
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-
}
636666
this._trigger('always', null, options);
637667
if (this._active === 0) {
638668
// The stop callback is triggered when all uploads have

0 commit comments

Comments
 (0)