mirror of
https://github.com/Tygs/0bin.git
synced 2023-08-10 21:13:00 +03:00
Main js filed passed jslint
This commit is contained in:
parent
c6d1c974d2
commit
2b2ab65b73
@ -1,3 +1,5 @@
|
|||||||
|
/*global sjcl:true, jQuery:true, $:true, lzw:true, zerobin:true, ZeroClipboard:true, vizhash:true, prettyPrint:true */
|
||||||
|
;(function(){
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
/* Start random number generator seeding ASAP */
|
/* Start random number generator seeding ASAP */
|
||||||
@ -17,8 +19,8 @@ $.ajaxSetup({ cache: true });
|
|||||||
function mkcb(func){
|
function mkcb(func){
|
||||||
var args = arguments;
|
var args = arguments;
|
||||||
return function(){
|
return function(){
|
||||||
return func.apply(func, Array.prototype.slice.call(args, 1))
|
return func.apply(func, Array.prototype.slice.call(args, 1));
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -28,7 +30,7 @@ function mkcb(func){
|
|||||||
****************************/
|
****************************/
|
||||||
|
|
||||||
|
|
||||||
var zerobin = {
|
window.zerobin = {
|
||||||
/** Base64 + compress + encrypt, with callbacks before each operation,
|
/** Base64 + compress + encrypt, with callbacks before each operation,
|
||||||
and all of them are executed in a timed continuation to give
|
and all of them are executed in a timed continuation to give
|
||||||
a change to the UI to respond.
|
a change to the UI to respond.
|
||||||
@ -40,21 +42,21 @@ var zerobin = {
|
|||||||
setTimeout (function(){
|
setTimeout (function(){
|
||||||
|
|
||||||
content = sjcl.codec.utf8String.toBits(content);
|
content = sjcl.codec.utf8String.toBits(content);
|
||||||
if (toBase64Callback) {toBase64Callback()}
|
if (toBase64Callback) {toBase64Callback();}
|
||||||
|
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
|
|
||||||
content = sjcl.codec.base64.fromBits(content);
|
content = sjcl.codec.base64.fromBits(content);
|
||||||
if (compressCallback) {compressCallback()}
|
if (compressCallback) {compressCallback();}
|
||||||
|
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
|
|
||||||
content = lzw.compress(content);
|
content = lzw.compress(content);
|
||||||
if (encryptCallback) {encryptCallback()}
|
if (encryptCallback) {encryptCallback();}
|
||||||
|
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
content = sjcl.encrypt(key, content);
|
content = sjcl.encrypt(key, content);
|
||||||
if (doneCallback) {doneCallback(content)}
|
if (doneCallback) {doneCallback(content);}
|
||||||
}, 250);
|
}, 250);
|
||||||
|
|
||||||
}, 250);
|
}, 250);
|
||||||
@ -81,7 +83,7 @@ var zerobin = {
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
content = sjcl.decrypt(key, content);
|
content = sjcl.decrypt(key, content);
|
||||||
if (uncompressCallback) {uncompressCallback()}
|
if (uncompressCallback) {uncompressCallback();}
|
||||||
|
|
||||||
/* Decompress */
|
/* Decompress */
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
@ -89,7 +91,7 @@ var zerobin = {
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
content = lzw.decompress(content);
|
content = lzw.decompress(content);
|
||||||
if (fromBase64Callback) {fromBase64Callback()}
|
if (fromBase64Callback) {fromBase64Callback();}
|
||||||
|
|
||||||
/* From base 64 to bits */
|
/* From base 64 to bits */
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
@ -97,14 +99,14 @@ var zerobin = {
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
content = sjcl.codec.base64.toBits(content);
|
content = sjcl.codec.base64.toBits(content);
|
||||||
if (toStringCallback) {toStringCallback()}
|
if (toStringCallback) {toStringCallback();}
|
||||||
|
|
||||||
/* From bits to string */
|
/* From bits to string */
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
|
|
||||||
try {
|
try {
|
||||||
content = sjcl.codec.utf8String.fromBits(content);
|
content = sjcl.codec.utf8String.fromBits(content);
|
||||||
if (doneCallback) {doneCallback(content)}
|
if (doneCallback) {doneCallback(content);}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
errorCallback(err);
|
errorCallback(err);
|
||||||
}
|
}
|
||||||
@ -137,19 +139,19 @@ var zerobin = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getFormatedDate: function(date){
|
getFormatedDate: function(date){
|
||||||
var date = date || new Date();
|
date = date || new Date();
|
||||||
return ((date.getMonth() +1 ) + '-' +
|
return ((date.getMonth() +1 ) + '-' +
|
||||||
date.getDate() + '-' + date.getFullYear());
|
date.getDate() + '-' + date.getFullYear());
|
||||||
},
|
},
|
||||||
|
|
||||||
getFormatedTime: function(date){
|
getFormatedTime: function(date){
|
||||||
var date = date || new Date();
|
date = date || new Date();
|
||||||
var h = date.getHours();
|
var h = date.getHours();
|
||||||
var m = date.getMinutes();
|
var m = date.getMinutes();
|
||||||
var s = date.getSeconds();
|
var s = date.getSeconds();
|
||||||
if (h < 10) {h = "0" + h}
|
if (h < 10) {h = "0" + h;}
|
||||||
if (m < 10) {m = "0" + m}
|
if (m < 10) {m = "0" + m;}
|
||||||
if (s < 10) {s = "0" + s}
|
if (s < 10) {s = "0" + s;}
|
||||||
return h + ":" + m + ":" + s;
|
return h + ":" + m + ":" + s;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -160,9 +162,10 @@ var zerobin = {
|
|||||||
getKeys: function(){
|
getKeys: function(){
|
||||||
var keys = [];
|
var keys = [];
|
||||||
for(var i = 0; i <= localStorage.length; i++){
|
for(var i = 0; i <= localStorage.length; i++){
|
||||||
if(localStorage.key(i) != null)
|
if(localStorage.key(i) !== null){
|
||||||
keys[i] = parseInt(localStorage.key(i), 10);
|
keys[i] = parseInt(localStorage.key(i), 10);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return keys.sort(zerobin.numOrdA);
|
return keys.sort(zerobin.numOrdA);
|
||||||
},
|
},
|
||||||
/** Get a tinyurl using JSONP */
|
/** Get a tinyurl using JSONP */
|
||||||
@ -193,7 +196,7 @@ var zerobin = {
|
|||||||
var val = !!(w.File && w.FileReader && w.FileList && w.Blob);
|
var val = !!(w.File && w.FileReader && w.FileList && w.Blob);
|
||||||
$('html').addClass((val ? '' : 'no-') + 'file-upload');
|
$('html').addClass((val ? '' : 'no-') + 'file-upload');
|
||||||
return val;
|
return val;
|
||||||
})(),
|
})()
|
||||||
},
|
},
|
||||||
|
|
||||||
storatePaste: function(url){
|
storatePaste: function(url){
|
||||||
@ -202,7 +205,7 @@ var zerobin = {
|
|||||||
zerobin.getFormatedTime() + ";" + url);
|
zerobin.getFormatedTime() + ";" + url);
|
||||||
var keys = zerobin.getKeys();
|
var keys = zerobin.getKeys();
|
||||||
|
|
||||||
if(keys.length < 1){keys[0] = 0}
|
if(keys.length < 1){keys[0] = 0;}
|
||||||
|
|
||||||
if (localStorage.length > 19) {
|
if (localStorage.length > 19) {
|
||||||
void localStorage.removeItem(keys[0]);
|
void localStorage.removeItem(keys[0]);
|
||||||
@ -223,14 +226,14 @@ var zerobin = {
|
|||||||
var paste = localStorage.getItem(keys[i]).split(';');
|
var paste = localStorage.getItem(keys[i]).split(';');
|
||||||
var displayDate = paste[0].split(' ')[0];
|
var displayDate = paste[0].split(' ')[0];
|
||||||
var prefix = 'the ';
|
var prefix = 'the ';
|
||||||
if (displayDate == date){
|
if (displayDate === date){
|
||||||
displayDate = paste[0].split(' ')[1];
|
displayDate = paste[0].split(' ')[1];
|
||||||
prefix = 'at ';
|
prefix = 'at ';
|
||||||
}
|
}
|
||||||
pastes.push({displayDate: displayDate, prefix: prefix, link: paste[1]});
|
pastes.push({displayDate: displayDate, prefix: prefix, link: paste[1]});
|
||||||
}
|
}
|
||||||
|
|
||||||
return pastes
|
return pastes;
|
||||||
},
|
},
|
||||||
|
|
||||||
/** Return an link object with the URL as href so you can extract host,
|
/** Return an link object with the URL as href so you can extract host,
|
||||||
@ -253,8 +256,13 @@ var zerobin = {
|
|||||||
})(),
|
})(),
|
||||||
|
|
||||||
getPasteId: function(url){
|
getPasteId: function(url){
|
||||||
var loc = url ? zerobin.parseUrl(url) : window.location
|
var loc = url ? zerobin.parseUrl(url) : window.location;
|
||||||
return loc.pathname.replace(/[/]|paste/g, '');
|
return loc.pathname.replace(/\/|paste/g, '').replace(/\?.*$/, '');
|
||||||
|
},
|
||||||
|
|
||||||
|
getPasteKey: function(url){
|
||||||
|
var loc = url ? zerobin.parseUrl(url) : window.location;
|
||||||
|
return loc.hash.replace('#', '').replace(/\?.*$/, '');
|
||||||
},
|
},
|
||||||
|
|
||||||
/** Return the paste content stripted from any code coloration */
|
/** Return the paste content stripted from any code coloration */
|
||||||
@ -285,14 +293,14 @@ var zerobin = {
|
|||||||
|
|
||||||
$(window).scrollTop(0);
|
$(window).scrollTop(0);
|
||||||
|
|
||||||
if (flush) {$('.alert-'+type).remove()}
|
if (flush) {$('.alert-'+type).remove();}
|
||||||
|
|
||||||
var $message = $('#alert-template').clone().attr('id', null)
|
var $message = $('#alert-template').clone().attr('id', null)
|
||||||
.addClass('alert alert-' + type);
|
.addClass('alert alert-' + type);
|
||||||
$('.message', $message).html(message);
|
$('.message', $message).html(message);
|
||||||
|
|
||||||
if (title) {$('.title', $message).html(title)}
|
if (title) {$('.title', $message).html(title);}
|
||||||
else {$('.title', $message).remove()}
|
else {$('.title', $message).remove();}
|
||||||
|
|
||||||
$message.prependTo($('#main')).show('fadeUp', callback);
|
$message.prependTo($('#main')).show('fadeUp', callback);
|
||||||
},
|
},
|
||||||
@ -301,7 +309,7 @@ var zerobin = {
|
|||||||
progressBar: function(selector){
|
progressBar: function(selector){
|
||||||
var $container = $(selector);
|
var $container = $(selector);
|
||||||
var bar = {container: $container, elem: $container.find('.bar')};
|
var bar = {container: $container, elem: $container.find('.bar')};
|
||||||
bar.set = function(text, rate){bar.elem.text(text).css('width', rate)};
|
bar.set = function(text, rate){bar.elem.text(text).css('width', rate);};
|
||||||
return bar;
|
return bar;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -332,10 +340,10 @@ $('.btn-primary').live("click", function(e){
|
|||||||
|
|
||||||
if (oversized){
|
if (oversized){
|
||||||
zerobin.message('error',
|
zerobin.message('error',
|
||||||
('Your file is <strong class="file-size">' + readablFfsize +
|
('Your file is <strong class="file-size">' + readableFsize +
|
||||||
'</strong>KB. You have reached the maximum size limit of ' +
|
'</strong>KB. You have reached the maximum size limit of ' +
|
||||||
readableMaxsize + 'KB.'),
|
readableMaxsize + 'KB.'),
|
||||||
'Warning!', true)
|
'Warning!', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!oversized && paste.trim()) {
|
if (!oversized && paste.trim()) {
|
||||||
@ -382,12 +390,12 @@ $('.btn-primary').live("click", function(e){
|
|||||||
.success(function(data) {
|
.success(function(data) {
|
||||||
bar.set('Redirecting to new paste...', '100%');
|
bar.set('Redirecting to new paste...', '100%');
|
||||||
|
|
||||||
if (data['status'] == 'error') {
|
if (data.status === 'error') {
|
||||||
zerobin.message('error', data['message'], 'Error');
|
zerobin.message('error', data.message, 'Error');
|
||||||
$form.prop('disabled', false);
|
$form.prop('disabled', false);
|
||||||
bar.container.hide();
|
bar.container.hide();
|
||||||
} else {
|
} else {
|
||||||
var paste_url = '/paste/' + data['paste'] + '#' + key;
|
var paste_url = '/paste/' + data.paste + '#' + key;
|
||||||
zerobin.storatePaste(paste_url);
|
zerobin.storatePaste(paste_url);
|
||||||
window.location = (paste_url);
|
window.location = (paste_url);
|
||||||
}
|
}
|
||||||
@ -411,7 +419,7 @@ $('.btn-primary').live("click", function(e){
|
|||||||
Also calculate and set the paste visual hash.
|
Also calculate and set the paste visual hash.
|
||||||
*/
|
*/
|
||||||
var content = $('#paste-content').text().trim();
|
var content = $('#paste-content').text().trim();
|
||||||
var key = window.location.hash.substring(1);
|
var key = zerobin.getPasteKey();
|
||||||
var error = false;
|
var error = false;
|
||||||
if (content && key) {
|
if (content && key) {
|
||||||
|
|
||||||
@ -467,7 +475,7 @@ if (content && key) {
|
|||||||
var clip = new ZeroClipboard.Client();
|
var clip = new ZeroClipboard.Client();
|
||||||
|
|
||||||
// Callback to reposition the clibpboad flash animation overlay
|
// Callback to reposition the clibpboad flash animation overlay
|
||||||
var reposition = function(){clip.reposition()};
|
var reposition = function(){clip.reposition();};
|
||||||
|
|
||||||
clip.addEventListener('mouseup', function(){
|
clip.addEventListener('mouseup', function(){
|
||||||
$('#clip-button').text('Copying paste...');
|
$('#clip-button').text('Copying paste...');
|
||||||
@ -493,7 +501,7 @@ if (content && key) {
|
|||||||
zerobin.message('success',
|
zerobin.message('success',
|
||||||
'<a href="' + tinyurl + '">' + tinyurl + '</a>',
|
'<a href="' + tinyurl + '">' + tinyurl + '</a>',
|
||||||
'Short url', true, reposition
|
'Short url', true, reposition
|
||||||
)
|
);
|
||||||
$('#short-url').text('Get short url');
|
$('#short-url').text('Get short url');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -542,7 +550,7 @@ $('#content').live('keyup change', function(){
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
if ($('.paste-option').length == 1) {
|
if ($('.paste-option').length === 1) {
|
||||||
$('.paste-option').clone().addClass('down').appendTo('form.well');
|
$('.paste-option').clone().addClass('down').appendTo('form.well');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -576,9 +584,9 @@ if (zerobin.support.localStorage){
|
|||||||
|
|
||||||
// hightlite the current link and make sure clicking the link
|
// hightlite the current link and make sure clicking the link
|
||||||
// does redirect to the page
|
// does redirect to the page
|
||||||
if (paste.link.replace(/#[^#]+/, '') == window.location.pathname){
|
if (paste.link.replace(/#[^#]+/, '') === window.location.pathname){
|
||||||
$li.addClass('active');
|
$li.addClass('active');
|
||||||
$link.click(function(){window.location.reload()});
|
$link.click(function(){window.location.reload();});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -614,7 +622,7 @@ if (zerobin.support.fileUpload) {
|
|||||||
$('#content').val(event.target.result).trigger('change');
|
$('#content').val(event.target.result).trigger('change');
|
||||||
};
|
};
|
||||||
reader.readAsText(files[0]);
|
reader.readAsText(files[0]);
|
||||||
}
|
};
|
||||||
|
|
||||||
var $buttonOverlay = $('#file-upload');
|
var $buttonOverlay = $('#file-upload');
|
||||||
var $button = $('.btn-upload');
|
var $button = $('.btn-upload');
|
||||||
@ -622,7 +630,7 @@ if (zerobin.support.fileUpload) {
|
|||||||
try {
|
try {
|
||||||
$button.val('Uploading...');
|
$button.val('Uploading...');
|
||||||
$button.prop('disabled', true);
|
$button.prop('disabled', true);
|
||||||
$buttonOverlay.change(function(){upload(this.files)});
|
$buttonOverlay.change(function(){upload(this.files);});
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
zerobin.message('error', 'Could no upload the file', 'Error');
|
zerobin.message('error', 'Could no upload the file', 'Error');
|
||||||
@ -657,3 +665,4 @@ $('.email-link').each(function(i, elem){
|
|||||||
|
|
||||||
}); /* End of "document ready" jquery callback */
|
}); /* End of "document ready" jquery callback */
|
||||||
|
|
||||||
|
})(); /* End of self executing function */
|
Loading…
Reference in New Issue
Block a user