summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/cheesesteak.js33
1 files changed, 19 insertions, 14 deletions
diff --git a/js/cheesesteak.js b/js/cheesesteak.js
index 8b1f09d..3447d97 100644
--- a/js/cheesesteak.js
+++ b/js/cheesesteak.js
@@ -159,13 +159,15 @@
});
xhr.open(opts.method, this.url, true);
- xhr.upload.addEventListener('loadstart', function() {
+
+ function initProgressBar(evt) {
for (i = 0; i < len; i++) {
files[i].uploadedSize = 0;
}
- });
+ }
+ xhr.upload.addEventListener('loadstart', initProgressBar);
- xhr.upload.addEventListener('progress', function(evt) {
+ function updateProgressBar(evt) {
var size;
if (evt.lengthComputable) {
@@ -190,23 +192,26 @@
}
_this.emit('uploadprogress', evt, files);
- }, false);
-
- xhr.upload.addEventListener('loadstart', function(evt) {
- _this.emit('uploadstart', evt);
- });
+ }
+ xhr.upload.addEventListener('progress', updateProgressBar, false);
- xhr.upload.addEventListener('load', function(evt) {
+ // The upload is complete, now tell the user to wait for URLs.
+ function postUpload(evt) {
_this.emit('uploadcomplete', evt);
- });
+ }
+ xhr.upload.addEventListener('load', postUpload);
- xhr.addEventListener('progress', function(evt) {
+ // Tell the browser the upload completed and wait for response.
+ function postProgress(evt) {
_this.emit('progress', evt);
- });
+ }
+ xhr.addEventListener('progress', postProgress);
- xhr.addEventListener('load', function(evt) {
+ // Send a success/error response. Nothing more to do.
+ function uploadFinished(evt) {
_this.emit('load', evt, xhr.responseText);
- });
+ }
+ xhr.addEventListener('load', uploadFinished);
xhr.send(data);