summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorJuuso Lapinlampi <wub@partyvan.eu>2015-10-09 17:59:48 +0200
committerJuuso Lapinlampi <wub@partyvan.eu>2015-10-09 17:59:48 +0200
commit24ce733985f9d220067654e51698b41c4b446fe7 (patch)
tree41752a06494e029ee3f8d10fbb5c03540da4d338 /js
parent575b78b9d679db2243083f9ecc8b1543b2a1af02 (diff)
Lint pomf.js vars declarations to top of function
Fixes ESLint vars-on-top errors using airbnb/legacy config.
Diffstat (limited to 'js')
-rw-r--r--js/pomf.js93
1 files changed, 45 insertions, 48 deletions
diff --git a/js/pomf.js b/js/pomf.js
index 0e2ecee..1e89576 100644
--- a/js/pomf.js
+++ b/js/pomf.js
@@ -29,36 +29,6 @@ $(function() {
var $btnContent = '';
- if (!$.hasFileAPI()) {
- $('#no-file-api').show();
- $uploadBtn.hide();
- }
-
- $uploadBtn.cabinet($uploadInput);
-
- $uploadBtn.on('dragenter', function(evt) {
- if (this === evt.target) {
- $(this).addClass('drop');
- $btnContent = $(this).html();
- $(this).html('Drop it here~');
- }
- });
-
- $uploadBtn.on('drop', function() {
- $(this).trigger('dragleave');
- });
-
- $uploadBtn.on('dragleave', function(evt) {
- var node = evt.target;
- do {
- if (node === this) {
- $(this).removeClass('drop');
- $(this).html($btnContent);
- break;
- }
- } while (node === node.parentNode);
- });
-
var MAX_SIZE = (function(node) {
var max = node.attr('data-max-size') || '120MiB';
var num = parseInt(/([0-9,]+).*/.exec(max)[1].replace(',', ''), 10);
@@ -92,40 +62,66 @@ $(function() {
return $rowItem;
};
- $uploadBtn.on('change', function() {
- $uploadFiles.empty().removeClass('error completed');
+ if (!$.hasFileAPI()) {
+ $('#no-file-api').show();
+ $uploadBtn.hide();
+ }
- var files = $uploadInput[0].filelist;
+ $uploadBtn.cabinet($uploadInput);
- files.forEach(function(file) {
- createRow(file.name, file.humanSize).appendTo($uploadFiles);
- });
+ $uploadBtn.on('dragenter', function(evt) {
+ if (this === evt.target) {
+ $(this).addClass('drop');
+ $btnContent = $(this).html();
+ $(this).html('Drop it here~');
+ }
+ });
- var totalRow = createRow('', files.humanSize, 'total');
- totalRow.appendTo($uploadFiles);
+ $uploadBtn.on('drop', function() {
+ $(this).trigger('dragleave');
+ });
- var $totalName = $('.file-name', totalRow);
+ $uploadBtn.on('dragleave', function(evt) {
+ var node = evt.target;
+ do {
+ if (node === this) {
+ $(this).removeClass('drop');
+ $(this).html($btnContent);
+ break;
+ }
+ } while (node === node.parentNode);
+ });
+ $uploadBtn.on('change', function() {
+ var files = $uploadInput[0].filelist;
+ var totalRow = createRow('', files.humanSize, 'total');
+ var $totalName = $('.file-name', totalRow);
var UPLOAD_ERR_MAX_SIZE = 'onii-chan y-your upload is t-too big&hellip;';
var UPLOAD_ERR_FAILED = 'Something went wrong; try again later.';
-
- if (files.size > MAX_SIZE) {
- $uploadFiles.addClass('error');
- $totalName.html(UPLOAD_ERR_MAX_SIZE);
- return;
- }
-
var up = files.upload('upload.php');
var eachRow = function(files, fn) {
var hits = {};
files.forEach(function(file) {
- ++hits[file.name];
var row = $($('li[data-filename="' +
escape(file.name) + '"]')[hits[file.name] || 0]);
+ ++hits[file.name];
fn.call(row, row, file, files);
});
};
+ $uploadFiles.empty().removeClass('error completed');
+
+ files.forEach(function(file) {
+ createRow(file.name, file.humanSize).appendTo($uploadFiles);
+ });
+
+ totalRow.appendTo($uploadFiles);
+
+ if (files.size > MAX_SIZE) {
+ $uploadFiles.addClass('error');
+ $totalName.html(UPLOAD_ERR_MAX_SIZE);
+ return;
+ }
up.on('uploadprogress', function(evt, files) {
eachRow(files, function(row, file, files) {
@@ -141,9 +137,10 @@ $(function() {
});
up.on('load', function(evt, response) {
+ var res = JSON.parse(response);
+
switch (evt.target.status) {
case 200:
- var res = JSON.parse(response);
if (!res.success) {
$uploadFiles.addClass('error');
$totalName.text(UPLOAD_ERR_FAILED);