diff options
| -rw-r--r-- | js/cabinet.js | 14 | ||||
| -rw-r--r-- | js/cheesesteak.js | 45 | ||||
| -rw-r--r-- | js/pomf.js | 22 |
3 files changed, 43 insertions, 38 deletions
diff --git a/js/cabinet.js b/js/cabinet.js index 2e2408b..09f4e71 100644 --- a/js/cabinet.js +++ b/js/cabinet.js @@ -31,7 +31,7 @@ var _this = this; var passthrough = function(outer, inner, prevent, fn) { - _this.on(outer, function(e) { + _this.on(outer, function(evt) { if (inner === 'click') { $input[0].click(); } else { @@ -39,19 +39,19 @@ } if (prevent) { - e.preventDefault(); + evt.preventDefault(); } if (fn) { - fn(e); + fn(evt); } }, false); }; $input[0].filelist = Object.create(FileList); - $input.on('change', function(e) { - this.filelist = e.target.files; + $input.on('change', function(evt) { + this.filelist = evt.target.files; _this.change(); }); @@ -59,8 +59,8 @@ passthrough('dragover', 'dragover', true); passthrough('dragleave', 'dragleave', true); passthrough('click', 'click', false); - passthrough('drop', 'dragleave', true, function(e) { - $input[0].filelist = e.dataTransfer.files; + passthrough('drop', 'dragleave', true, function(evt) { + $input[0].filelist = evt.dataTransfer.files; _this.change(); }); }; diff --git a/js/cheesesteak.js b/js/cheesesteak.js index ee357f1..513573c 100644 --- a/js/cheesesteak.js +++ b/js/cheesesteak.js @@ -40,11 +40,14 @@ }; EventEmitter.prototype.emit = function(evt) { + var len = this._events[evt].length; + var i; + if (!this.hasOwnProperty('_events') || evt in this._events === false) { return; } - for (var i = 0, l = this._events[evt].length; i < l; i++) { + for (i = 0; i < len; i++) { this._events[evt][i].apply(this, Array.prototype.slice.call(arguments, 1)); } @@ -73,8 +76,8 @@ var units = [ 'B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB', ]; - var e = Math.floor(Math.log(this.size) / Math.log(1024)); - return (this.size / Math.pow(1024, e)).toFixed(2) + ' ' + units[e]; + var base = Math.floor(Math.log(this.size) / Math.log(1024)); + return (this.size / Math.pow(1024, base)).toFixed(2) + ' ' + units[base]; }, }; Object.defineProperty(FileList.prototype, 'humanSize', humanSize); @@ -136,13 +139,15 @@ FileListUploader.prototype = Object.create(EventEmitter.prototype); FileListUploader.prototype.upload = function(cb) { - if (cb) { - this.on('uploadcomplete', cb); - } - var opts = this.opts; var files = this.files; var _this = this; + var len = files.length; + var i; + + if (cb) { + this.on('uploadcomplete', cb); + } var data = new FormData(); files.forEach(function(file) { @@ -153,16 +158,16 @@ xhr.open(opts.method, this.url, true); - function initProgressBar(e) { - for (var i = 0, l = files.length; i < l; i++) { + function initProgressBar(evt) { + for (i = 0; i < len; i++) { files[i].uploadedSize = 0; } } xhr.upload.addEventListener('loadstart', initProgressBar); - function updateProgressBar(e) { - if (e.lengthComputable) { - var size = e.loaded; + function updateProgressBar(evt) { + if (evt.lengthComputable) { + var size = evt.loaded; /** * We know the size of the files, the order they're in, and how @@ -172,7 +177,7 @@ */ // TODO: This math has trouble on later uploads. Leak somewhere. - for (var i = 0, l = files.length; i < l; i++) { + for (i = 0; i < len; i++) { files[i].uploadedSize = Math.min(size, files[i].size); size -= files[i].uploadedSize; if (size <= 0) { @@ -182,25 +187,25 @@ } } - _this.emit('uploadprogress', e, files); + _this.emit('uploadprogress', evt, files); } xhr.upload.addEventListener('progress', updateProgressBar, false); // The upload is complete, now tell the user to wait for URLs. - function postUpload(e) { - _this.emit('uploadcomplete', e); + function postUpload(evt) { + _this.emit('uploadcomplete', evt); } xhr.upload.addEventListener('load', postUpload); // Tell the browser the upload completed and wait for response. - function postProgress(e) { - _this.emit('progress', e); + function postProgress(evt) { + _this.emit('progress', evt); } xhr.addEventListener('progress', postProgress); // Send a success/error response. Nothing more to do. - function uploadFinished(e) { - _this.emit('load', e, xhr.responseText); + function uploadFinished(evt) { + _this.emit('load', evt, xhr.responseText); } xhr.addEventListener('load', uploadFinished); @@ -36,20 +36,20 @@ $(function() { $uploadBtn.cabinet($uploadInput); - $uploadBtn.on('dragenter', function(e) { - if (this === e.target) { + $uploadBtn.on('dragenter', function(evt) { + if (this === evt.target) { $(this).addClass('drop'); $btnContent = $(this).html(); $(this).html('Drop it here~'); } }); - $uploadBtn.on('drop', function(e) { + $uploadBtn.on('drop', function() { $(this).trigger('dragleave'); }); - $uploadBtn.on('dragleave', function(e) { - var node = e.target; + $uploadBtn.on('dragleave', function(evt) { + var node = evt.target; do { if (node === this) { $(this).removeClass('drop'); @@ -92,7 +92,7 @@ $(function() { return $rowItem; }; - $uploadBtn.on('change', function(e) { + $uploadBtn.on('change', function() { $uploadFiles.empty().removeClass('error completed'); var files = $uploadInput[0].filelist; @@ -127,7 +127,7 @@ $(function() { }); }; - up.on('uploadprogress', function(e, files) { + up.on('uploadprogress', function(evt, files) { eachRow(files, function(row, file, files) { $('.progress-inner', row).width((file.percentUploaded * 100) + '%'); }); @@ -135,13 +135,13 @@ $(function() { $('.progress-inner', totalRow).width((files.percentUploaded * 100) + '%'); }); - up.on('uploadcomplete', function(e) { + up.on('uploadcomplete', function() { $('.progress-inner').width('100%'); $totalName.html('Grabbing URLs…'); }); - up.on('load', function(e, response) { - switch (e.target.status) { + up.on('load', function(evt, response) { + switch (evt.target.status) { case 200: var res = JSON.parse(response); if (!res.success) { @@ -150,7 +150,7 @@ $(function() { break; } - eachRow(res.files, function(row, file, files) { + eachRow(res.files, function(row, file) { var $link = $('<a>'); $link.attr('href', file.url) |
