From 5462c603b6b9389fd7ea8e55998045a4452d2d7d Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Sun, 27 Sep 2015 21:41:12 +0000 Subject: Prefix jQuery object variables with a $ While JSCS and ESLint do not detect this yet as of today, my eyes do. The Airbnb style guide wants to do this. This commit doesn't prefix cabinet.js, but the next commit will while addressing another issue. --- js/pomf.js | 92 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/js/pomf.js b/js/pomf.js index 1a11543..db68ed8 100644 --- a/js/pomf.js +++ b/js/pomf.js @@ -23,37 +23,37 @@ /* jshint browser:true, jquery:true */ $(function() { - var uploadInput = $('#upload-input'); - var uploadBtn = $('#upload-btn'); - var uploadFiles = $('#upload-filelist'); + var $uploadInput = $('#upload-input'); + var $uploadBtn = $('#upload-btn'); + var $uploadFiles = $('#upload-filelist'); - var btnContent = ''; + var $btnContent = ''; if (!$.hasFileAPI()) { $('#no-file-api').show(); - uploadBtn.hide(); + $uploadBtn.hide(); } - uploadBtn.cabinet(uploadInput); + $uploadBtn.cabinet($uploadInput); - uploadBtn.on('dragenter', function(e) { + $uploadBtn.on('dragenter', function(e) { if (this === e.target) { $(this).addClass('drop'); - btnContent = $(this).html(); + $btnContent = $(this).html(); $(this).html('Drop it here~'); } }); - uploadBtn.on('drop', function(e) { + $uploadBtn.on('drop', function(e) { $(this).trigger('dragleave'); }); - uploadBtn.on('dragleave', function(e) { + $uploadBtn.on('dragleave', function(e) { node = e.target; do { if (node === this) { $(this).removeClass('drop'); - $(this).html(btnContent); + $(this).html($btnContent); break; } } while (node === node.parentNode); @@ -70,48 +70,48 @@ $(function() { ); return num * oneUnit; - })(uploadInput); + })($uploadInput); var createRow = function(filename, size, extra) { - var rowItem = $('
  • '); - var rowName = $(''); - var rowProg = $('
    '); - var rowSize = $(''); - var rowUrl = $(''); + var $rowItem = $('
  • '); + var $rowName = $(''); + var $rowProg = $('
    '); + var $rowSize = $(''); + var $rowUrl = $(''); - rowItem.addClass(extra || ''); + $rowItem.addClass(extra || ''); - $('
    ').appendTo(rowProg); + $('
    ').appendTo($rowProg); - rowItem.attr('data-filename', escape(filename)); - rowName.text(filename); - rowSize.text(size); + $rowItem.attr('data-filename', escape(filename)); + $rowName.text(filename); + $rowSize.text(size); - rowItem.append(rowName, rowProg, rowSize, rowUrl); + $rowItem.append($rowName, $rowProg, $rowSize, $rowUrl); - return rowItem; + return $rowItem; }; - uploadBtn.on('change', function(e) { - uploadFiles.empty().removeClass('error completed'); + $uploadBtn.on('change', function(e) { + $uploadFiles.empty().removeClass('error completed'); - var files = uploadInput[0].filelist; + var files = $uploadInput[0].filelist; files.forEach(function(file) { - createRow(file.name, file.humanSize).appendTo(uploadFiles); + createRow(file.name, file.humanSize).appendTo($uploadFiles); }); var totalRow = createRow('', files.humanSize, 'total'); - totalRow.appendTo(uploadFiles); + totalRow.appendTo($uploadFiles); - var totalName = $('.file-name', totalRow); + var $totalName = $('.file-name', totalRow); var UPLOAD_ERR_MAX_SIZE = 'onii-chan y-your upload is t-too big…'; var UPLOAD_ERR_FAILED = 'Something went wrong; try again later.'; if (files.size > MAX_SIZE) { - uploadFiles.addClass('error'); - totalName.html(UPLOAD_ERR_MAX_SIZE); + $uploadFiles.addClass('error'); + $totalName.html(UPLOAD_ERR_MAX_SIZE); return; } @@ -137,7 +137,7 @@ $(function() { up.on('uploadcomplete', function(e) { $('.progress-inner').width('100%'); - totalName.html('Grabbing URLs…'); + $totalName.html('Grabbing URLs…'); }); up.on('load', function(e, response) { @@ -145,31 +145,31 @@ $(function() { case 200: var res = JSON.parse(response); if (!res.success) { - uploadFiles.addClass('error'); - totalName.text(UPLOAD_ERR_FAILED); + $uploadFiles.addClass('error'); + $totalName.text(UPLOAD_ERR_FAILED); break; } eachRow(res.files, function(row, file, files) { - var link = $(''); + var $link = $(''); - link.attr('href', file.url) - .attr('target', '_BLANK') - .text(file.url.replace('http://', '').replace('https://', '')); + $link.attr('href', file.url) + .attr('target', '_BLANK') + .text(file.url.replace('http://', '').replace('https://', '')); - $('.file-url', row).append(link); + $('.file-url', row).append($link); }); - uploadFiles.addClass('completed'); - totalName.text('Done!'); + $uploadFiles.addClass('completed'); + $totalName.text('Done!'); break; case 413: - uploadFiles.addClass('error completed'); - totalName.html(UPLOAD_ERR_MAX_SIZE); + $uploadFiles.addClass('error completed'); + $totalName.html(UPLOAD_ERR_MAX_SIZE); break; default: - uploadFiles.addClass('error completed'); - totalName.text(UPLOAD_ERR_FAILED); + $uploadFiles.addClass('error completed'); + $totalName.text(UPLOAD_ERR_FAILED); } }); -- cgit v1.2.3 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(-) 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