diff options
| author | Juuso Lapinlampi <wub@partyvan.eu> | 2015-10-11 18:17:42 +0200 |
|---|---|---|
| committer | Juuso Lapinlampi <wub@partyvan.eu> | 2015-10-11 18:17:42 +0200 |
| commit | 6d93e72a544440d7c4cb0609cf6a3dc0f801f5f4 (patch) | |
| tree | e9612f209eed5a1c6be08ff64ff19af6ddcbed9f | |
| parent | bcfadb7deb7c8930df3a5142d43097391f4e9fa1 (diff) | |
| parent | d3f9e9a2929301b19a69ade53a6051859883f7f8 (diff) | |
Merge branch 'refactor-cheesesteak' into fix-eslint-warnings-2
Events now fire faster. Fixes ESLint func-names warnings using
airbnb/legacy config.
| -rw-r--r-- | js/cheesesteak.js | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/js/cheesesteak.js b/js/cheesesteak.js index 7280177..ee357f1 100644 --- a/js/cheesesteak.js +++ b/js/cheesesteak.js @@ -152,13 +152,15 @@ var xhr = new XMLHttpRequest(); xhr.open(opts.method, this.url, true); - xhr.upload.addEventListener('loadstart', function(e) { + + function initProgressBar(e) { for (var i = 0, l = files.length; i < l; i++) { files[i].uploadedSize = 0; } - }); + } + xhr.upload.addEventListener('loadstart', initProgressBar); - xhr.upload.addEventListener('progress', function(e) { + function updateProgressBar(e) { if (e.lengthComputable) { var size = e.loaded; @@ -181,23 +183,26 @@ } _this.emit('uploadprogress', e, files); - }, false); - - xhr.upload.addEventListener('loadstart', function(e) { - _this.emit('uploadstart', e); - }); + } + xhr.upload.addEventListener('progress', updateProgressBar, false); - xhr.upload.addEventListener('load', function(e) { + // The upload is complete, now tell the user to wait for URLs. + function postUpload(e) { _this.emit('uploadcomplete', e); - }); + } + xhr.upload.addEventListener('load', postUpload); - xhr.addEventListener('progress', function(e) { + // Tell the browser the upload completed and wait for response. + function postProgress(e) { _this.emit('progress', e); - }); + } + xhr.addEventListener('progress', postProgress); - xhr.addEventListener('load', function(e) { + // Send a success/error response. Nothing more to do. + function uploadFinished(e) { _this.emit('load', e, xhr.responseText); - }); + } + xhr.addEventListener('load', uploadFinished); xhr.send(data); |
