summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/cheesesteak.js33
1 files changed, 19 insertions, 14 deletions
diff --git a/js/cheesesteak.js b/js/cheesesteak.js
index 661d4b7..513573c 100644
--- a/js/cheesesteak.js
+++ b/js/cheesesteak.js
@@ -157,13 +157,15 @@
var xhr = new XMLHttpRequest();
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) {
if (evt.lengthComputable) {
var size = evt.loaded;
@@ -186,23 +188,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);