From 8d9f781514cdb07a33e2dbaa3431928f0e08733b Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Sun, 27 Sep 2015 16:00:12 +0000 Subject: Use strict node === node.parentNode comparison Fixes ESLint no-cond-assign warning. -- Sat, 26 Sep 2015 -- 10:38:42 +bursey | while (node = node.parentNode) is invalid 10:38:54 +bursey | should be while (node == node.parentNode) 10:40:38 +bursey | weird actually 10:40:55 +bursey | Elements tend to be "true" in js 10:41:16 +bursey | but if the parentNode is undefined, then it's | false 10:41:50 +bursey | thus it doesn't loop infinitely 10:43:00 +bursey | actually, use === instead of == --- js/pomf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/pomf.js') diff --git a/js/pomf.js b/js/pomf.js index bdd3174..bb14e15 100644 --- a/js/pomf.js +++ b/js/pomf.js @@ -56,7 +56,7 @@ $(function() { $(this).html(btnContent); break; } - } while (node = node.parentNode); + } while (node === node.parentNode); }); var MAX_SIZE = (function(node) { -- cgit v1.2.3 From d9eb9c94c32c1065e9166e055f9a355841b2b8db Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Sun, 27 Sep 2015 16:08:46 +0000 Subject: Remove unused expression (hits[file.name] = 0) Fixes ESLint no-unused-expressions warning. --- js/pomf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/pomf.js') diff --git a/js/pomf.js b/js/pomf.js index bb14e15..f4fbeb2 100644 --- a/js/pomf.js +++ b/js/pomf.js @@ -120,7 +120,7 @@ $(function() { var eachRow = function(files, fn) { var hits = {}; files.forEach(function(file) { - ++hits[file.name] || (hits[file.name] = 0); + ++hits[file.name]; var row = $($('li[data-filename="' + escape(file.name) + '"]')[hits[file.name] || 0]); fn.call(row, row, file, files); -- cgit v1.2.3 From 2c7ced1f503299e6ede6d3ef2b5e115318f5401f Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Sun, 27 Sep 2015 18:27:24 +0000 Subject: Fix redeclaration of "res" variable in pomf.js Fixes ESLint warning no-redeclare. --- js/pomf.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/pomf.js') diff --git a/js/pomf.js b/js/pomf.js index f4fbeb2..2e810de 100644 --- a/js/pomf.js +++ b/js/pomf.js @@ -139,10 +139,10 @@ $(function() { totalName.html('Grabbing URLs…'); }); - up.on('load', function(e, res) { + up.on('load', function(e, response) { switch (e.target.status) { case 200: - var res = JSON.parse(res); + var res = JSON.parse(response); if (!res.success) { uploadFiles.addClass('error'); totalName.text(UPLOAD_ERR_FAILED); -- 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/pomf.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'js/pomf.js') diff --git a/js/pomf.js b/js/pomf.js index 2e810de..5690e60 100644 --- a/js/pomf.js +++ b/js/pomf.js @@ -131,6 +131,7 @@ $(function() { eachRow(files, function(row, file, files) { $('.progress-inner', row).width((file.percentUploaded * 100) + '%'); }); + $('.progress-inner', totalRow).width((files.percentUploaded * 100) + '%'); }); @@ -148,6 +149,7 @@ $(function() { totalName.text(UPLOAD_ERR_FAILED); break; } + eachRow(res.files, function(row, file, files) { var link = $(''); @@ -157,6 +159,7 @@ $(function() { $('.file-url', row).append(link); }); + uploadFiles.addClass('completed'); totalName.text('Done!'); break; @@ -168,7 +171,9 @@ $(function() { uploadFiles.addClass('error completed'); totalName.text(UPLOAD_ERR_FAILED); } + }); + up.upload(); }); }); -- 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/pomf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/pomf.js') diff --git a/js/pomf.js b/js/pomf.js index 5690e60..5a359da 100644 --- a/js/pomf.js +++ b/js/pomf.js @@ -121,7 +121,7 @@ $(function() { var hits = {}; files.forEach(function(file) { ++hits[file.name]; - var row = $($('li[data-filename="' + + var row = $($('li[data-filename="' + escape(file.name) + '"]')[hits[file.name] || 0]); fn.call(row, row, file, files); }); -- cgit v1.2.3 From f1c92f57d6a5ae01b8c67bf3f6d1189f41537339 Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Sun, 27 Sep 2015 19:22:31 +0000 Subject: Use individual Javascript var declarations Thanks to ASI (Automatic Semicolon Insertion) in JavaScript, not using individual var declarations can actually cause subtle bugs. Fixes JSCS disallowMultipleVarDecl warnings using Airbnb preset. Reference: http://benalman.com/news/2012/05/multiple-var-statements-javascript/ --- js/pomf.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'js/pomf.js') diff --git a/js/pomf.js b/js/pomf.js index 5a359da..2d4ff58 100644 --- a/js/pomf.js +++ b/js/pomf.js @@ -23,9 +23,9 @@ /* jshint browser:true, jquery:true */ $(function() { - var uploadInput = $('#upload-input'), - uploadBtn = $('#upload-btn'), - uploadFiles = $('#upload-filelist'); + var uploadInput = $('#upload-input'); + var uploadBtn = $('#upload-btn'); + var uploadFiles = $('#upload-filelist'); var btnContent = ''; @@ -73,11 +73,11 @@ $(function() { })(uploadInput); var createRow = function(filename, size, extra) { - var rowItem = $('
  • '), - rowName = $(''), - rowProg = $('
    '), - rowSize = $(''), - rowUrl = $(''); + var rowItem = $('
  • '); + var rowName = $(''); + var rowProg = $('
    '); + var rowSize = $(''); + var rowUrl = $(''); rowItem.addClass(extra || ''); -- cgit v1.2.3 From e4c38033bb3c8e4f44ba93e604652d9eb8e9b0b8 Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Sun, 27 Sep 2015 20:58:05 +0000 Subject: Fix JS switch ... case indentation This is a surprising one. JSHint and JSCS do not seem to mind the previous indentation, but ESLint throws an error when using the Airbnb style guide. The style guide itself doesn't seem to mention anything about this directly. What ever it is, this one pleases all three linters. Fixes ESLint indent warnings using Airbnb ES5 config. --- js/pomf.js | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'js/pomf.js') diff --git a/js/pomf.js b/js/pomf.js index 2d4ff58..1a11543 100644 --- a/js/pomf.js +++ b/js/pomf.js @@ -142,34 +142,34 @@ $(function() { up.on('load', function(e, response) { switch (e.target.status) { - case 200: - var res = JSON.parse(response); - if (!res.success) { - uploadFiles.addClass('error'); - totalName.text(UPLOAD_ERR_FAILED); - break; - } - - eachRow(res.files, function(row, file, files) { - var link = $(''); - - link.attr('href', file.url) - .attr('target', '_BLANK') - .text(file.url.replace('http://', '').replace('https://', '')); - - $('.file-url', row).append(link); - }); - - uploadFiles.addClass('completed'); - totalName.text('Done!'); - break; - case 413: - uploadFiles.addClass('error completed'); - totalName.html(UPLOAD_ERR_MAX_SIZE); - break; - default: - uploadFiles.addClass('error completed'); + case 200: + var res = JSON.parse(response); + if (!res.success) { + uploadFiles.addClass('error'); totalName.text(UPLOAD_ERR_FAILED); + break; + } + + eachRow(res.files, function(row, file, files) { + var link = $(''); + + link.attr('href', file.url) + .attr('target', '_BLANK') + .text(file.url.replace('http://', '').replace('https://', '')); + + $('.file-url', row).append(link); + }); + + uploadFiles.addClass('completed'); + totalName.text('Done!'); + break; + case 413: + uploadFiles.addClass('error completed'); + totalName.html(UPLOAD_ERR_MAX_SIZE); + break; + default: + uploadFiles.addClass('error completed'); + totalName.text(UPLOAD_ERR_FAILED); } }); -- cgit v1.2.3 From 42a100ef0e4ec9681dad66029912c7748baf33bc Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Sun, 27 Sep 2015 22:02:53 +0000 Subject: Add pomf.js parseInt() radix 10 Fixes ESLint radix warning using Airbnb ES5 config. --- js/pomf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/pomf.js') diff --git a/js/pomf.js b/js/pomf.js index 1a11543..187aa58 100644 --- a/js/pomf.js +++ b/js/pomf.js @@ -61,7 +61,7 @@ $(function() { var MAX_SIZE = (function(node) { var max = node.attr('data-max-size') || '120MiB'; - var num = parseInt(/([0-9,]+).*/.exec(max)[1].replace(',', '')); + var num = parseInt(/([0-9,]+).*/.exec(max)[1].replace(',', ''), 10); var unit = /(?:([KMGTPEZY])(i)?B|([BKMGTPEZY]))/.exec(max) || ['B', '', '']; var oneUnit = Math.pow( -- cgit v1.2.3 From 3c281a369d6c86a4008aeef96b58d87f0e1e0858 Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Sun, 27 Sep 2015 22:09:35 +0000 Subject: Remove extra newline padding from pomf.js This newline was accidentally introduced in commit a17c446. Fixes ESLint warning padded-blocks using Airbnb ES5 config. --- js/pomf.js | 1 - 1 file changed, 1 deletion(-) (limited to 'js/pomf.js') diff --git a/js/pomf.js b/js/pomf.js index 187aa58..7dd44ef 100644 --- a/js/pomf.js +++ b/js/pomf.js @@ -171,7 +171,6 @@ $(function() { uploadFiles.addClass('error completed'); totalName.text(UPLOAD_ERR_FAILED); } - }); up.upload(); -- cgit v1.2.3