From 408e3cf72b993655ae3b8f8eeb9f8a7b95d21c54 Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Mon, 28 Sep 2015 16:08:36 +0000 Subject: Prefix cheesesteak.js jQuery object variables with a $ This fixes Airbnb ES5 style guide violations. --- js/cabinet.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'js/cabinet.js') diff --git a/js/cabinet.js b/js/cabinet.js index 2f3a3a6..8414df2 100644 --- a/js/cabinet.js +++ b/js/cabinet.js @@ -27,15 +27,15 @@ }; $.fn.cabinet = function(input) { - input = $(input); + var $input = $(input); var _this = this; var passthrough = function(outer, inner, prevent, fn) { _this.on(outer, function(e) { if (inner === 'click') { - input[0].click(); + $input[0].click(); } else { - input.trigger(inner); + $input.trigger(inner); } if (prevent) { @@ -48,9 +48,9 @@ }, false); }; - input[0].filelist = Object.create(FileList); + $input[0].filelist = Object.create(FileList); - input.on('change', function(e) { + $input.on('change', function(e) { this.filelist = e.target.files; _this.change(); }); @@ -60,7 +60,7 @@ passthrough('dragleave', 'dragleave', true); passthrough('click', 'click', false); passthrough('drop', 'dragleave', true, function(e) { - input[0].filelist = e.dataTransfer.files; + $input[0].filelist = e.dataTransfer.files; _this.change(); }); }; -- cgit v1.2.3 From 08dfe39b91ef17357bfc91734266b560b463aaff Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Mon, 28 Sep 2015 17:05:14 +0000 Subject: Fix assignments to function parameters in JavaScript Fixes ESLint no-param-reassing warning. --- js/cabinet.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/cabinet.js') diff --git a/js/cabinet.js b/js/cabinet.js index 2f3a3a6..74a250a 100644 --- a/js/cabinet.js +++ b/js/cabinet.js @@ -26,8 +26,8 @@ return (window.FormData !== undefined); }; - $.fn.cabinet = function(input) { - input = $(input); + $.fn.cabinet = function(uploadInput) { + var input = $(uploadInput); var _this = this; var passthrough = function(outer, inner, prevent, fn) { -- cgit v1.2.3 From 187f3000385f136c8766fbfb2d18d24832ecf4b5 Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Mon, 28 Sep 2015 19:03:34 +0000 Subject: Fix unexpected use of undefined with Boolean() Airbnb style guide recommends checking booleans this way or using (!!window.FormData). The latter is more confusing for many. While !! is indeed 0.2% faster than Boolean(), it's called micro-optimization. There is no noticeable difference to the user in our use scenario and I prefer more readable code any day. Fixes ESLint no-undefined warning using Airbnb ES5 config. Reference: https://jsperf.com/boolean-conversion-speed --- js/cabinet.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/cabinet.js') diff --git a/js/cabinet.js b/js/cabinet.js index 2f3a3a6..a74bb40 100644 --- a/js/cabinet.js +++ b/js/cabinet.js @@ -23,7 +23,7 @@ /* jshint browser:true, jquery:true */ (function($) { $.hasFileAPI = function hasFileAPI() { - return (window.FormData !== undefined); + return Boolean(window.FormData); }; $.fn.cabinet = function(input) { -- cgit v1.2.3 From 575b78b9d679db2243083f9ecc8b1543b2a1af02 Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Fri, 9 Oct 2015 15:04:21 +0000 Subject: Lint cheesesteak.js and cabinet.js id-length < 2 Fixes ESLint id-length errors using airbnb/legacy config. Variable "i" is ignored as an exception. I've also avoided creating new errors with these changes, so this also fixes some no-unused-vars and avoids creating vars-on-top errors. --- js/cabinet.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'js/cabinet.js') 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(); }); }; -- cgit v1.2.3 From a46c5d3a4d7d7bae4e1001923806cfcee8d71b35 Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Wed, 18 Nov 2015 13:46:22 +0000 Subject: Rename identifier "$" to "cabinet" in cabinet.js Very short identifier names usually make the code harder to read and potentially less maintainable. Fixes two ESLint id-length errors using airbnb/legacy config. Suggested-by: avail --- js/cabinet.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/cabinet.js') diff --git a/js/cabinet.js b/js/cabinet.js index 09f4e71..b820d9b 100644 --- a/js/cabinet.js +++ b/js/cabinet.js @@ -21,8 +21,8 @@ */ /* jshint browser:true, jquery:true */ -(function($) { - $.hasFileAPI = function hasFileAPI() { +(function(cabinet) { + cabinet.hasFileAPI = function hasFileAPI() { return Boolean(window.FormData); }; -- cgit v1.2.3