summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/cabinet.js16
-rw-r--r--js/cheesesteak.js22
-rw-r--r--js/pomf.js94
3 files changed, 66 insertions, 66 deletions
diff --git a/js/cabinet.js b/js/cabinet.js
index 2f3a3a6..2e2408b 100644
--- a/js/cabinet.js
+++ b/js/cabinet.js
@@ -23,19 +23,19 @@
/* jshint browser:true, jquery:true */
(function($) {
$.hasFileAPI = function hasFileAPI() {
- return (window.FormData !== undefined);
+ return Boolean(window.FormData);
};
- $.fn.cabinet = function(input) {
- input = $(input);
+ $.fn.cabinet = function(uploadInput) {
+ var $input = $(uploadInput);
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();
});
};
diff --git a/js/cheesesteak.js b/js/cheesesteak.js
index e090a12..ee357f1 100644
--- a/js/cheesesteak.js
+++ b/js/cheesesteak.js
@@ -23,7 +23,7 @@
/* jshint browser:true, jquery:true */
(function() {
// Lightweight EventEmitter implementation
- EventEmitter = function() {};
+ var EventEmitter = function() {};
EventEmitter.prototype.on = function(evt, fn) {
this._events = this._events || {};
@@ -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);
@@ -125,13 +125,13 @@
this.url = url;
this.files = files;
- opts = opts || {};
+ var request = opts || {};
this.opts = merge({
field: 'files[]',
method: 'POST',
- data: {}
- }, opts);
+ data: {},
+ }, request);
};
FileListUploader.prototype = Object.create(EventEmitter.prototype);
@@ -162,7 +162,7 @@
function updateProgressBar(e) {
if (e.lengthComputable) {
- size = e.loaded;
+ var size = e.loaded;
/**
* We know the size of the files, the order they're in, and how
diff --git a/js/pomf.js b/js/pomf.js
index 7dd44ef..a108c4b 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) {
- node = e.target;
+ $uploadBtn.on('dragleave', function(e) {
+ var 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 = $('<li class=file>');
- var rowName = $('<span class=file-name>');
- var rowProg = $('<div class="file-progress progress-outer">');
- var rowSize = $('<span class=file-size>');
- var rowUrl = $('<span class=file-url>');
+ var $rowItem = $('<li class=file>');
+ var $rowName = $('<span class=file-name>');
+ var $rowProg = $('<div class="file-progress progress-outer">');
+ var $rowSize = $('<span class=file-size>');
+ var $rowUrl = $('<span class=file-url>');
- rowItem.addClass(extra || '');
+ $rowItem.addClass(extra || '');
- $('<div class=progress-inner>').appendTo(rowProg);
+ $('<div class=progress-inner>').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&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);
+ $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&hellip;');
+ $totalName.html('Grabbing URLs&hellip;');
});
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 = $('<a>');
+ var $link = $('<a>');
- 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);
}
});