From 758893d3df999464a3f7a4ebda0937e515094fce Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Sun, 27 Sep 2015 17:00:59 +0000 Subject: Fix irregular whitespace in cheesesteak.js Fixes ESLint warnings about no-irregular-whitespace. --- js/cheesesteak.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'js/cheesesteak.js') diff --git a/js/cheesesteak.js b/js/cheesesteak.js index a3cf991..112b2c7 100644 --- a/js/cheesesteak.js +++ b/js/cheesesteak.js @@ -30,13 +30,13 @@ this._events[evt].push(fn); }; EventEmitter.prototype.off = function(evt, fn) { - if (!this.hasOwnProperty('_events') || evt in this._events === false) { + if (!this.hasOwnProperty('_events') || evt in this._events === false) { return; } this._events[evt].splice(this._events[evt].indexOf(fn), 1); }; EventEmitter.prototype.emit = function(evt) { - if (!this.hasOwnProperty('_events') || evt in this._events === false) { + if (!this.hasOwnProperty('_events') || evt in this._events === false) { return; } @@ -109,7 +109,7 @@ for (var key in overlay) { if (typeof overlay[key] === 'object') { out[key] = merge(base[key], overlay[key]); - } else { + } else { out[key] = overlay[key]; } } -- cgit v1.2.3 From a17c4461869fc93e48c00cbb12dc588aa9b25f89 Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Sun, 27 Sep 2015 18:57:51 +0000 Subject: Add missing newlines after blocks Fixes JSCS requirePaddingNewLinesAfterBlocks warnings using Airbnb preset. --- js/cheesesteak.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'js/cheesesteak.js') diff --git a/js/cheesesteak.js b/js/cheesesteak.js index 112b2c7..75f837e 100644 --- a/js/cheesesteak.js +++ b/js/cheesesteak.js @@ -24,17 +24,21 @@ (function() { /* Lightweight EventEmitter implementation */ EventEmitter = function() {}; + EventEmitter.prototype.on = function(evt, fn) { this._events = this._events || {}; this._events[evt] = this._events[evt] || []; this._events[evt].push(fn); }; + EventEmitter.prototype.off = function(evt, fn) { if (!this.hasOwnProperty('_events') || evt in this._events === false) { return; } + this._events[evt].splice(this._events[evt].indexOf(fn), 1); }; + EventEmitter.prototype.emit = function(evt) { if (!this.hasOwnProperty('_events') || evt in this._events === false) { return; @@ -113,6 +117,7 @@ out[key] = overlay[key]; } } + return out; }; @@ -128,6 +133,7 @@ 'data': {} }, opts); }; + FileListUploader.prototype = Object.create(EventEmitter.prototype); FileListUploader.prototype.upload = function(cb) { if (cb) { @@ -151,6 +157,7 @@ files[i].uploadedSize = 0; } }); + xhr.upload.addEventListener('progress', function(e) { if (e.lengthComputable) { size = e.loaded; @@ -168,17 +175,22 @@ } } } + events.emit('uploadprogress', e, files); }, false); + xhr.upload.addEventListener('loadstart', function(e) { events.emit('uploadstart', e); }); + xhr.upload.addEventListener('load', function(e) { events.emit('uploadcomplete', e); }); + xhr.addEventListener('progress', function(e) { events.emit('progress', e); }); + xhr.addEventListener('load', function(e) { events.emit('load', e, xhr.responseText); }); -- cgit v1.2.3 From ff40b2b485d71f2fdd1432f743ae4ee8567254b3 Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Sun, 27 Sep 2015 19:07:38 +0000 Subject: Fix illegal trailing whitespace in JavaScript Fixes JSCS disallowTrailingWhitespace warnings using Airbnb preset. --- js/cheesesteak.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/cheesesteak.js') diff --git a/js/cheesesteak.js b/js/cheesesteak.js index 75f837e..1e60a56 100644 --- a/js/cheesesteak.js +++ b/js/cheesesteak.js @@ -162,7 +162,7 @@ if (e.lengthComputable) { size = e.loaded; // We know the size of the files, the order they're in, and how - // much we've uploaded. Based on this data, we can do some magic + // much we've uploaded. Based on this data, we can do some magic // to figure out which file we're on, and how much we've uploaded // of that file. // TODO: This math has trouble on later uploads. Leak somewhere -- cgit v1.2.3 From c2681b55d6e6643ab113e6f0945a443793a34fab Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Sun, 27 Sep 2015 19:14:28 +0000 Subject: Change double quotes to single quotes in cheesesteak.js Fixes JSCS validateQuoteMarks warnings using Airbnb preset. --- js/cheesesteak.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'js/cheesesteak.js') diff --git a/js/cheesesteak.js b/js/cheesesteak.js index 1e60a56..6cdeb77 100644 --- a/js/cheesesteak.js +++ b/js/cheesesteak.js @@ -59,7 +59,7 @@ FileList.prototype.reduce = Array.prototype.reduce; FileList.prototype.reduceRight = Array.prototype.reduceRight; - Object.defineProperty(FileList.prototype, "size", { + Object.defineProperty(FileList.prototype, 'size', { get: function getSize() { return this.reduce(function(prev, curr) { return prev + curr.size; @@ -71,25 +71,25 @@ var humanSize = { get: function humanSize() { var units = [ - "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB" + '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]; + return (this.size / Math.pow(1024, e)).toFixed(2) + ' ' + units[e]; } }; - Object.defineProperty(FileList.prototype, "humanSize", humanSize); - Object.defineProperty(File.prototype, "humanSize", humanSize); + Object.defineProperty(FileList.prototype, 'humanSize', humanSize); + Object.defineProperty(File.prototype, 'humanSize', humanSize); var percentUploaded = { get: function percentUploaded() { return this.uploadedSize / this.size; } }; - Object.defineProperty(FileList.prototype, "percentUploaded", + Object.defineProperty(FileList.prototype, 'percentUploaded', percentUploaded); - Object.defineProperty(File.prototype, "percentUploaded", percentUploaded); + Object.defineProperty(File.prototype, 'percentUploaded', percentUploaded); - Object.defineProperty(FileList.prototype, "uploadedSize", { + Object.defineProperty(FileList.prototype, 'uploadedSize', { get: function getUploadedSize() { return this.reduce(function(prev, curr) { return prev + (curr.uploadedSize || 0); @@ -98,7 +98,7 @@ }); /* Object URL stuff */ - Object.defineProperty(File.prototype, "url", { + Object.defineProperty(File.prototype, 'url', { get: function getURL() { return window.URL.createObjectURL(this); } -- cgit v1.2.3 From cd23640ded6a29071d5b46a6594efa3ad5ac7c2b Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Sun, 27 Sep 2015 19:34:56 +0000 Subject: Fix cheesesteak.js comments to follow Airbnb style Airbnb says to use /** ... */ for multiline comments and // for single line comments. Fixes JSCS requirePaddingNewLinesBeforeLineComments and validateIndentation warnings using Airbnb preset. --- js/cheesesteak.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'js/cheesesteak.js') diff --git a/js/cheesesteak.js b/js/cheesesteak.js index 6cdeb77..a8b0d02 100644 --- a/js/cheesesteak.js +++ b/js/cheesesteak.js @@ -22,7 +22,7 @@ /* jshint browser:true, jquery:true */ (function() { - /* Lightweight EventEmitter implementation */ + // Lightweight EventEmitter implementation EventEmitter = function() {}; EventEmitter.prototype.on = function(evt, fn) { @@ -50,7 +50,7 @@ } }; - /* Copy the stuff from Array to FileList */ + // Copy the stuff from Array to FileList FileList.prototype.forEach = Array.prototype.forEach; FileList.prototype.every = Array.prototype.every; FileList.prototype.some = Array.prototype.some; @@ -67,7 +67,7 @@ } }); - /* Utility to convert bytes into human units */ + // Utility to convert bytes into human units var humanSize = { get: function humanSize() { var units = [ @@ -97,7 +97,7 @@ } }); - /* Object URL stuff */ + // Object URL stuff Object.defineProperty(File.prototype, 'url', { get: function getURL() { return window.URL.createObjectURL(this); @@ -161,11 +161,15 @@ xhr.upload.addEventListener('progress', function(e) { if (e.lengthComputable) { size = e.loaded; - // We know the size of the files, the order they're in, and how - // much we've uploaded. Based on this data, we can do some magic - // to figure out which file we're on, and how much we've uploaded - // of that file. - // TODO: This math has trouble on later uploads. Leak somewhere + + /** + * We know the size of the files, the order they're in, and how + * much we've uploaded. Based on this data, we can do some magic + * to figure out which file we're on, and how much we've uploaded + * of that file. + */ + + // TODO: This math has trouble on later uploads. Leak somewhere. for (var i = 0, l = files.length; i < l; i++) { files[i].uploadedSize = Math.min(size, files[i].size); size -= files[i].uploadedSize; @@ -196,7 +200,8 @@ }); xhr.send(data); - /* TODO: Add more event passthroughs, maybe abstract it into a helper? */ + + // TODO: Add more event passthroughs, maybe abstract it into a helper? }; FileList.prototype.upload = function uploadFileList(url, opts) { -- cgit v1.2.3 From e6f354a9be648a366df39b9dac75eb58a99490dd Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Sun, 27 Sep 2015 19:48:08 +0000 Subject: Add missing commas before closing bracket/curly brace This adds commas to cheesesteak.js. Something to note, the Airbnb ES5 style guide opposes a trailing comma. The latest ES6 edition endorses adding a trailing comma, explaining it leads to cleaner Git diffs. Endorse the ES6 standard, that's also the Airbnb preset in JSCS. Fixes JSCS requireTrailingComma warnings using Airbnb preset. --- js/cheesesteak.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'js/cheesesteak.js') diff --git a/js/cheesesteak.js b/js/cheesesteak.js index a8b0d02..fcfe607 100644 --- a/js/cheesesteak.js +++ b/js/cheesesteak.js @@ -64,18 +64,18 @@ return this.reduce(function(prev, curr) { return prev + curr.size; }, 0); - } + }, }); // Utility to convert bytes into human units var humanSize = { get: function humanSize() { var units = [ - 'B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB' + '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]; - } + }, }; Object.defineProperty(FileList.prototype, 'humanSize', humanSize); Object.defineProperty(File.prototype, 'humanSize', humanSize); @@ -83,7 +83,7 @@ var percentUploaded = { get: function percentUploaded() { return this.uploadedSize / this.size; - } + }, }; Object.defineProperty(FileList.prototype, 'percentUploaded', percentUploaded); @@ -94,14 +94,14 @@ return this.reduce(function(prev, curr) { return prev + (curr.uploadedSize || 0); }, 0); - } + }, }); // Object URL stuff Object.defineProperty(File.prototype, 'url', { get: function getURL() { return window.URL.createObjectURL(this); - } + }, }); File.revokeURL = function revokeURL(url) { window.URL.revokeObjectURL(url); @@ -130,7 +130,7 @@ this.opts = merge({ 'field': 'files[]', 'method': 'POST', - 'data': {} + 'data': {}, }, opts); }; -- cgit v1.2.3 From 86649a2283531fe289470d916786d1e11225ffe3 Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Sun, 27 Sep 2015 19:55:03 +0000 Subject: Remove extra quotes to follow Airbnb JavaScript style Fixes JSCS disallowQuotedKeysInObjects warnings using Airbnb preset. --- js/cheesesteak.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'js/cheesesteak.js') diff --git a/js/cheesesteak.js b/js/cheesesteak.js index fcfe607..d47cf5c 100644 --- a/js/cheesesteak.js +++ b/js/cheesesteak.js @@ -128,9 +128,9 @@ opts = opts || {}; this.opts = merge({ - 'field': 'files[]', - 'method': 'POST', - 'data': {}, + field: 'files[]', + method: 'POST', + data: {}, }, opts); }; -- cgit v1.2.3 From a78072eba23ec544462c7a4fae8e4899f51632a7 Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Sun, 27 Sep 2015 19:59:22 +0000 Subject: cheesesteak.js: Use _this to save reference to this Fixes JSCS safeContextKeyword warnings using Airbnb preset. --- js/cheesesteak.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'js/cheesesteak.js') diff --git a/js/cheesesteak.js b/js/cheesesteak.js index d47cf5c..0ea701d 100644 --- a/js/cheesesteak.js +++ b/js/cheesesteak.js @@ -142,7 +142,7 @@ var opts = this.opts; var files = this.files; - var events = this; + var _this = this; var data = new FormData(); files.forEach(function(file) { @@ -180,23 +180,23 @@ } } - events.emit('uploadprogress', e, files); + _this.emit('uploadprogress', e, files); }, false); xhr.upload.addEventListener('loadstart', function(e) { - events.emit('uploadstart', e); + _this.emit('uploadstart', e); }); xhr.upload.addEventListener('load', function(e) { - events.emit('uploadcomplete', e); + _this.emit('uploadcomplete', e); }); xhr.addEventListener('progress', function(e) { - events.emit('progress', e); + _this.emit('progress', e); }); xhr.addEventListener('load', function(e) { - events.emit('load', e, xhr.responseText); + _this.emit('load', e, xhr.responseText); }); xhr.send(data); -- cgit v1.2.3 From 49d58d98f5866bb9ccc9069a16d131486f04bba2 Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Sun, 27 Sep 2015 22:15:19 +0000 Subject: Remove previously added missing brace/bracket commas Until the code has been converted to ES6 in it's entirety, let's stick to Airbnb's ES5 style guide so that ESLint won't complain. This reverts commit e6f354a. --- js/cheesesteak.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'js/cheesesteak.js') diff --git a/js/cheesesteak.js b/js/cheesesteak.js index 0ea701d..ea3dc19 100644 --- a/js/cheesesteak.js +++ b/js/cheesesteak.js @@ -64,18 +64,18 @@ return this.reduce(function(prev, curr) { return prev + curr.size; }, 0); - }, + } }); // Utility to convert bytes into human units var humanSize = { get: function humanSize() { var units = [ - 'B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB', + '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]; - }, + } }; Object.defineProperty(FileList.prototype, 'humanSize', humanSize); Object.defineProperty(File.prototype, 'humanSize', humanSize); @@ -83,7 +83,7 @@ var percentUploaded = { get: function percentUploaded() { return this.uploadedSize / this.size; - }, + } }; Object.defineProperty(FileList.prototype, 'percentUploaded', percentUploaded); @@ -94,14 +94,14 @@ return this.reduce(function(prev, curr) { return prev + (curr.uploadedSize || 0); }, 0); - }, + } }); // Object URL stuff Object.defineProperty(File.prototype, 'url', { get: function getURL() { return window.URL.createObjectURL(this); - }, + } }); File.revokeURL = function revokeURL(url) { window.URL.revokeObjectURL(url); @@ -130,7 +130,7 @@ this.opts = merge({ field: 'files[]', method: 'POST', - data: {}, + data: {} }, opts); }; -- cgit v1.2.3