2012-05-12 12:33:01 +04:00
|
|
|
/*global sjcl:true, jQuery:true, $:true, lzw:true, zerobin:true, ZeroClipboard:true, vizhash:true, prettyPrint:true, confirm:true */
|
2013-01-19 22:40:44 +04:00
|
|
|
;
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/* Start random number generator seeding ASAP */
|
|
|
|
sjcl.random.startCollectors();
|
|
|
|
/* Ensure jquery use cache for ajax requests */
|
|
|
|
$.ajaxSetup({
|
|
|
|
cache: true
|
|
|
|
});
|
2012-04-24 22:15:38 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/** Create a function that create inline callbacks.
|
2012-05-06 21:24:46 +04:00
|
|
|
We use it to create callbacks for onliners with static arguments
|
|
|
|
E.G:
|
|
|
|
$('stuff').hide(function()(console.log(1, 2, 3)))
|
|
|
|
|
|
|
|
Becomes:
|
|
|
|
|
|
|
|
$('stuff').hide(mkcb(console.log, 1, 2, 3))
|
2013-01-19 22:40:44 +04:00
|
|
|
*/
|
|
|
|
function mkcb(func) {
|
|
|
|
var args = arguments;
|
|
|
|
return function () {
|
|
|
|
return func.apply(func, Array.prototype.slice.call(args, 1));
|
|
|
|
};
|
|
|
|
}
|
2012-05-06 21:24:46 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/***************************
|
|
|
|
**** 0bin utilities ***
|
|
|
|
***************************/
|
2012-05-06 21:24:46 +04:00
|
|
|
|
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
window.zerobin = {
|
2012-04-29 21:50:39 +04:00
|
|
|
/** Base64 + compress + encrypt, with callbacks before each operation,
|
|
|
|
and all of them are executed in a timed continuation to give
|
|
|
|
a change to the UI to respond.
|
|
|
|
*/
|
2012-05-22 21:58:23 +04:00
|
|
|
version: '0.1.1',
|
2013-01-19 22:40:44 +04:00
|
|
|
encrypt: function (key, content, toBase64Callback,
|
|
|
|
compressCallback, encryptCallback, doneCallback) {
|
2012-04-29 13:42:23 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
setTimeout(function () {
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
content = sjcl.codec.utf8String.toBits(content);
|
|
|
|
if (toBase64Callback) {
|
|
|
|
toBase64Callback();
|
|
|
|
}
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
setTimeout(function () {
|
2012-04-29 21:50:39 +04:00
|
|
|
|
|
|
|
content = sjcl.codec.base64.fromBits(content);
|
2013-01-19 22:40:44 +04:00
|
|
|
if (compressCallback) {
|
|
|
|
compressCallback();
|
|
|
|
}
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
setTimeout(function () {
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
// content = lzw.compress(content); // Create a bug with JPG
|
|
|
|
if (encryptCallback) {
|
|
|
|
encryptCallback();
|
|
|
|
}
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
setTimeout(function () {
|
|
|
|
try {
|
|
|
|
content = sjcl.encrypt(key, content);
|
|
|
|
} catch (e) {
|
|
|
|
$('input, textarea, select, button').prop('disabled', false);
|
|
|
|
zerobin.progressBar('form.well .progress').container.hide();
|
|
|
|
|
|
|
|
zerobin.message('error', 'Paste could not be encrypted. Aborting.',
|
2013-01-19 20:05:37 +04:00
|
|
|
'Error');
|
2013-01-19 22:40:44 +04:00
|
|
|
}
|
|
|
|
if (doneCallback) {
|
|
|
|
doneCallback(content);
|
|
|
|
}
|
2012-04-29 21:50:39 +04:00
|
|
|
}, 250);
|
|
|
|
|
|
|
|
}, 250);
|
|
|
|
|
|
|
|
}, 250);
|
|
|
|
|
|
|
|
}, 250);
|
2013-01-19 22:40:44 +04:00
|
|
|
},
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/** Base64 decoding + uncompress + decrypt, with callbacks before each operation,
|
2012-04-29 21:50:39 +04:00
|
|
|
and all of them are executed in a timed continuation to give
|
|
|
|
a change to the UI to respond.
|
|
|
|
|
|
|
|
This is where using a library to fake synchronicity could start to be
|
|
|
|
useful, this code is starting be difficult to read. If anyone read this
|
|
|
|
and got a suggestion, by all means, speak your mind.
|
2013-01-19 22:40:44 +04:00
|
|
|
*/
|
|
|
|
decrypt: function (key, content, errorCallback, uncompressCallback,
|
|
|
|
fromBase64Callback, toStringCallback, doneCallback) {
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* Decrypt */
|
|
|
|
setTimeout(function () {
|
|
|
|
try {
|
|
|
|
content = sjcl.decrypt(key, content);
|
|
|
|
if (uncompressCallback) {
|
|
|
|
uncompressCallback();
|
|
|
|
}
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* Decompress */
|
|
|
|
setTimeout(function () {
|
|
|
|
try {
|
|
|
|
content = lzw.decompress(content);
|
|
|
|
if (fromBase64Callback) {
|
|
|
|
fromBase64Callback();
|
|
|
|
}
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* From base 64 to bits */
|
|
|
|
setTimeout(function () {
|
|
|
|
try {
|
|
|
|
content = sjcl.codec.base64.toBits(content);
|
|
|
|
if (toStringCallback) {
|
|
|
|
toStringCallback();
|
2012-04-29 21:50:39 +04:00
|
|
|
}
|
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* From bits to string */
|
|
|
|
setTimeout(function () {
|
|
|
|
try {
|
|
|
|
content = sjcl.codec.utf8String.fromBits(content);
|
|
|
|
if (doneCallback) {
|
|
|
|
doneCallback(content);
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
errorCallback(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
}, 250); /* "End of from bits to string" */
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
errorCallback(err);
|
|
|
|
}
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
}, 250); /* End of "from base 64 to bits" */
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
} catch (err) {
|
|
|
|
errorCallback(err);
|
|
|
|
}
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
}, 250); /* End of "decompress" */
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
} catch (err) {
|
|
|
|
errorCallback(err);
|
|
|
|
}
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
}, 250); /* End of "decrypt" */
|
|
|
|
},
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-04-29 23:05:19 +04:00
|
|
|
/** Create a random base64-like string long enought to be suitable as
|
|
|
|
an encryption key */
|
|
|
|
makeKey: function (entropy) {
|
|
|
|
entropy = Math.ceil(entropy / 6) * 6; /* non-6-multiple produces same-length base64 */
|
|
|
|
var key = sjcl.bitArray.clamp(
|
|
|
|
sjcl.random.randomWords(Math.ceil(entropy / 32), 0), entropy );
|
|
|
|
return sjcl.codec.base64.fromBits(key, 0).replace(/\=+$/, '').replace(/\//, '-');
|
2013-01-19 22:40:44 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
getFormatedDate: function (date) {
|
|
|
|
date = date || new Date();
|
|
|
|
return ((date.getMonth() + 1) + '-' + date.getDate() + '-' + date.getFullYear());
|
|
|
|
},
|
|
|
|
|
|
|
|
getFormatedTime: function (date) {
|
|
|
|
date = date || new Date();
|
|
|
|
var h = date.getHours(),
|
2012-05-23 20:46:18 +04:00
|
|
|
m = date.getMinutes(),
|
|
|
|
s = date.getSeconds();
|
2013-01-19 22:40:44 +04:00
|
|
|
if (h < 10) {
|
|
|
|
h = "0" + h;
|
|
|
|
}
|
|
|
|
if (m < 10) {
|
|
|
|
m = "0" + m;
|
|
|
|
}
|
|
|
|
if (s < 10) {
|
|
|
|
s = "0" + s;
|
|
|
|
}
|
|
|
|
return h + ":" + m + ":" + s;
|
|
|
|
},
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
numOrdA: function (a, b) {
|
|
|
|
return (a - b);
|
|
|
|
},
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/** Return a reverse sorted list of all the keys in local storage that
|
2012-05-16 20:44:56 +04:00
|
|
|
are prefixed with with the passed version (default being this lib
|
|
|
|
version) */
|
2013-01-19 22:40:44 +04:00
|
|
|
getLocalStorageKeys: function () {
|
|
|
|
var version = 'zerobinV0.1';
|
|
|
|
var keys = [];
|
|
|
|
for (var key in localStorage) {
|
|
|
|
if (key.indexOf(version) !== -1) {
|
2012-05-16 20:44:56 +04:00
|
|
|
keys.push(key);
|
2013-01-19 22:40:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
keys.sort();
|
|
|
|
keys.reverse();
|
|
|
|
return keys;
|
|
|
|
},
|
2012-05-06 21:24:46 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/** Get a tinyurl using JSONP */
|
2013-01-24 12:55:48 +04:00
|
|
|
getTinyURL: function(longURL, success) {
|
|
|
|
$.ajax({
|
|
|
|
url: 'https://www.googleapis.com/urlshortener/v1/url',
|
|
|
|
type: 'POST',
|
|
|
|
contentType: 'application/json',
|
|
|
|
data: JSON.stringify({
|
|
|
|
"longUrl": longURL
|
|
|
|
}),
|
|
|
|
processData: false,
|
|
|
|
dataType: 'json'
|
|
|
|
}).done(function(data){
|
|
|
|
success(data.id);
|
|
|
|
});
|
2013-01-19 22:40:44 +04:00
|
|
|
},
|
2012-05-06 21:24:46 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/** Check for browser support of the named featured. Store the result
|
|
|
|
and add a class to the html tag with the result */
|
|
|
|
support: {
|
|
|
|
localStorage: (function () {
|
|
|
|
var val = !! (localStorage);
|
|
|
|
$('html').addClass((val ? '' : 'no-') + 'local-storage');
|
|
|
|
return val;
|
|
|
|
})(),
|
|
|
|
|
|
|
|
history: (function () {
|
|
|
|
var val = !! (window.history && history.pushState);
|
|
|
|
$('html').addClass((val ? '' : 'no-') + 'history');
|
|
|
|
return val;
|
|
|
|
})(),
|
|
|
|
|
|
|
|
fileUpload: (function () {
|
|
|
|
var w = window;
|
|
|
|
var val = !! (w.File && w.FileReader && w.FileList && w.Blob);
|
|
|
|
$('html').addClass((val ? '' : 'no-') + 'file-upload');
|
|
|
|
return val;
|
|
|
|
})()
|
|
|
|
},
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/** Store the paste of a URL in local storate, with a storage format
|
2012-05-16 20:44:56 +04:00
|
|
|
version prefix and the paste date as the key */
|
2013-01-19 22:40:44 +04:00
|
|
|
storePaste: function (url, date) {
|
2012-04-29 13:42:23 +04:00
|
|
|
|
2012-05-16 20:44:56 +04:00
|
|
|
date = date || new Date();
|
2013-01-19 22:40:44 +04:00
|
|
|
date = (date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + zerobin.getFormatedTime(date));
|
2012-05-16 20:44:56 +04:00
|
|
|
|
|
|
|
var keys = zerobin.getLocalStorageKeys();
|
2012-04-29 13:42:23 +04:00
|
|
|
|
2012-05-06 21:24:46 +04:00
|
|
|
if (localStorage.length > 19) {
|
2012-05-16 20:44:56 +04:00
|
|
|
void localStorage.removeItem(keys[19]);
|
2012-05-06 21:24:46 +04:00
|
|
|
}
|
|
|
|
|
2012-05-16 20:53:24 +04:00
|
|
|
localStorage.setItem('zerobinV' + zerobin.version + "#" + date, url);
|
2013-01-19 22:40:44 +04:00
|
|
|
},
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/** Return a list of the previous paste url with the creation date
|
2012-05-16 20:44:56 +04:00
|
|
|
If the paste is from today, date format should be "at hh:ss",
|
|
|
|
else it should be "the mm-dd-yyy"
|
|
|
|
*/
|
2013-01-19 22:40:44 +04:00
|
|
|
getPreviousPastes: function () {
|
|
|
|
var pastes = [],
|
2012-05-16 20:44:56 +04:00
|
|
|
keys = zerobin.getLocalStorageKeys(),
|
|
|
|
today = zerobin.getFormatedDate();
|
2012-05-06 21:24:46 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
$.each(keys, function (i, key) {
|
|
|
|
var pasteDateTime = key.replace(/^[^#]+#/, '');
|
|
|
|
var displayDate = pasteDateTime.match(/^(\d+)-(\d+)-(\d+)\s/);
|
|
|
|
displayDate = displayDate[2] + '-' + displayDate[3] + '-' + displayDate[1];
|
|
|
|
var prefix = 'the ';
|
|
|
|
if (displayDate === today) {
|
|
|
|
displayDate = pasteDateTime.split(' ')[1];
|
|
|
|
prefix = 'at ';
|
|
|
|
}
|
|
|
|
pastes.push({
|
|
|
|
displayDate: displayDate,
|
|
|
|
prefix: prefix,
|
|
|
|
link: localStorage.getItem(key)
|
|
|
|
});
|
|
|
|
});
|
2012-05-06 21:24:46 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
return pastes;
|
|
|
|
},
|
2012-05-06 21:24:46 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/** Return an link object with the URL as href so you can extract host,
|
2012-05-08 14:52:17 +04:00
|
|
|
protocol, hash, etc.
|
|
|
|
|
|
|
|
This function use a closure to store a <div> parent for the <a>
|
|
|
|
because IE requires the link be processed by it's HTML parser
|
|
|
|
for the URL to be parsed. */
|
2013-01-19 22:40:44 +04:00
|
|
|
parseUrl: (function () {
|
2012-05-08 14:52:17 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
var div = document.createElement('div');
|
|
|
|
div.innerHTML = "<a></a>";
|
2012-05-08 14:52:17 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
return function (url) {
|
|
|
|
div.firstChild.href = url;
|
|
|
|
div.innerHTML = div.innerHTML;
|
|
|
|
return div.firstChild;
|
|
|
|
};
|
2012-05-08 14:52:17 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
})(),
|
2012-05-06 21:24:46 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
getPasteId: function (url) {
|
|
|
|
var loc = url ? zerobin.parseUrl(url) : window.location;
|
|
|
|
return loc.pathname.replace(/\/|paste/g, '');
|
|
|
|
},
|
2012-05-12 12:15:09 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
getPasteKey: function (url) {
|
|
|
|
var loc = url ? zerobin.parseUrl(url) : window.location;
|
|
|
|
return loc.hash.replace('#', '').replace(/(\?|&).*$/, '');
|
|
|
|
},
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/** Return the paste content stripted from any code coloration */
|
|
|
|
getPasteContent: function () {
|
|
|
|
var copy = '';
|
|
|
|
$("#paste-content li").each(function (index) {
|
|
|
|
copy = copy + $(this).text().replace(/[\u00a0]+/g, ' ') + '\n';
|
|
|
|
});
|
2013-01-31 17:00:53 +04:00
|
|
|
if (copy == '') {
|
|
|
|
copy = $("#paste-content").text();
|
|
|
|
}
|
2013-01-19 22:40:44 +04:00
|
|
|
return copy;
|
|
|
|
},
|
|
|
|
|
|
|
|
/** Return an approximate estimate the number of bytes in a text */
|
|
|
|
count: function (text, options) {
|
|
|
|
// Set option defaults
|
|
|
|
var crlf = /(\r?\n|\r)/g;
|
|
|
|
var whitespace = /(\r?\n|\r|\s+)/g;
|
|
|
|
options = options || {};
|
|
|
|
options.lineBreaks = options.lineBreaks || 1;
|
|
|
|
|
|
|
|
var length = text.length,
|
|
|
|
nonAscii = length - text.replace(/[\u0100-\uFFFF]/g, '').length,
|
2012-04-30 00:15:11 +04:00
|
|
|
lineBreaks = length - text.replace(crlf, '').length;
|
|
|
|
|
|
|
|
return length + nonAscii + Math.max(0, options.lineBreaks * (lineBreaks - 1));
|
2013-01-19 22:40:44 +04:00
|
|
|
},
|
|
|
|
/** Create a message, style it and insert it in the alert box */
|
|
|
|
message: function (type, message, title, flush, callback) {
|
|
|
|
$(window).scrollTop(0);
|
2012-05-01 19:57:48 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
if (flush) {
|
|
|
|
$('.alert-' + type).remove();
|
|
|
|
}
|
2012-04-30 00:15:11 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
var $message = $('#alert-template').clone().attr('id', null)
|
|
|
|
.addClass('alert alert-' + type);
|
|
|
|
$('.message', $message).html(message);
|
2012-04-30 00:15:11 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
if (title) {
|
|
|
|
$('.title', $message).html(title);
|
|
|
|
} else {
|
|
|
|
$('.title', $message).remove();
|
|
|
|
}
|
2012-04-30 00:15:11 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
$message.prependTo($('#main')).show('fadeUp', callback);
|
|
|
|
},
|
2012-05-06 21:24:46 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/** Return a progress bar object */
|
|
|
|
progressBar: function (selector) {
|
|
|
|
var $container = $(selector);
|
|
|
|
var bar = {
|
|
|
|
container: $container,
|
|
|
|
elem: $container.find('.bar')
|
|
|
|
};
|
|
|
|
bar.set = function (text, rate) {
|
|
|
|
bar.elem.text(text).css('width', rate);
|
|
|
|
};
|
|
|
|
return bar;
|
|
|
|
},
|
2012-05-22 21:10:54 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/** Return an integer ranking the probability this text is any kind of
|
2012-05-22 21:10:54 +04:00
|
|
|
source code. */
|
2013-01-19 22:40:44 +04:00
|
|
|
isCode: function (text) {
|
2012-05-22 21:10:54 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
var code_chars = /[A-Z]{3}[A-Z]+|\.[a-z]|[=:<>{}\[\]$_'"&]| {2}|\t/g;
|
|
|
|
var comments = /(:?\/\*|<!--)(:?.|\n)*?(:?\*\/|-->)|(\/\/|#)(.*?)\n/g;
|
|
|
|
var formating = /[-*=_+]{4,}/;
|
2012-05-22 21:10:54 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
var total = 0;
|
|
|
|
var size = 0;
|
|
|
|
var m = text.match(comments);
|
|
|
|
if (m) {
|
|
|
|
total += text.match(comments).length;
|
|
|
|
}
|
|
|
|
text = text.replace(comments, '');
|
|
|
|
text.replace(formating, '');
|
|
|
|
text = text.split('\n');
|
|
|
|
for (var i = 0; i < text.length; i++) {
|
2012-05-22 21:10:54 +04:00
|
|
|
var line = text[i];
|
|
|
|
size += line.length;
|
2012-09-07 19:07:53 +04:00
|
|
|
var match = line.replace(formating, '').match(code_chars);
|
2012-05-22 21:10:54 +04:00
|
|
|
if (match) {
|
2013-01-19 22:40:44 +04:00
|
|
|
total += match.length;
|
2012-05-22 21:10:54 +04:00
|
|
|
}
|
2013-01-19 22:40:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return total * 1000 / size;
|
|
|
|
},
|
|
|
|
|
|
|
|
// prevent defaults
|
|
|
|
ignoreDrag: function (e) {
|
|
|
|
e.originalEvent.stopPropagation();
|
|
|
|
e.originalEvent.preventDefault();
|
|
|
|
},
|
2012-05-22 21:10:54 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
// Handle Drop
|
|
|
|
handleDrop: function (e) {
|
2013-01-24 13:51:49 +04:00
|
|
|
e.originalEvent.preventDefault();
|
2013-01-19 22:40:44 +04:00
|
|
|
zerobin.upload(e.originalEvent.dataTransfer.files);
|
|
|
|
$("#content").removeClass('hover');
|
|
|
|
},
|
|
|
|
|
|
|
|
handleDragOver: function (e) {
|
|
|
|
zerobin.ignoreDrag(e);
|
|
|
|
$(this).addClass('hover');
|
|
|
|
},
|
|
|
|
|
|
|
|
handleDragLeave: function (e) {
|
|
|
|
$(this).removeClass('hover');
|
|
|
|
},
|
|
|
|
|
|
|
|
upload: function (files) {
|
|
|
|
var current_file = files[0];
|
|
|
|
var reader = new FileReader();
|
|
|
|
if (current_file.type.indexOf('image') == 0) {
|
|
|
|
reader.onload = function (event) {
|
|
|
|
var image = new Image();
|
|
|
|
image.src = event.target.result;
|
|
|
|
|
|
|
|
image.onload = function() {
|
|
|
|
var maxWidth = 1024,
|
|
|
|
maxHeight = 1024,
|
|
|
|
imageWidth = image.width,
|
|
|
|
imageHeight = image.height;
|
|
|
|
|
|
|
|
|
|
|
|
if (imageWidth > imageHeight) {
|
|
|
|
if (imageWidth > maxWidth) {
|
|
|
|
imageHeight *= maxWidth / imageWidth;
|
|
|
|
imageWidth = maxWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (imageHeight > maxHeight) {
|
|
|
|
imageWidth *= maxHeight / imageHeight;
|
|
|
|
imageHeight = maxHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var canvas = document.createElement('canvas');
|
|
|
|
canvas.width = imageWidth;
|
|
|
|
canvas.height = imageHeight;
|
|
|
|
image.width = imageWidth;
|
|
|
|
image.height = imageHeight;
|
|
|
|
var ctx = canvas.getContext("2d");
|
|
|
|
ctx.drawImage(this, 0, 0, imageWidth, imageHeight);
|
2013-04-23 01:15:24 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
var paste = canvas.toDataURL(current_file.type);
|
|
|
|
$('#content').val(paste).trigger('change');
|
|
|
|
$('#content').hide();
|
|
|
|
$(image).css('max-width', '742px');
|
|
|
|
$('#content').after(image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reader.readAsDataURL(current_file);
|
|
|
|
} else {
|
|
|
|
reader.onload = function (event) {
|
|
|
|
$('#content').val(event.target.result).trigger('change');
|
|
|
|
};
|
|
|
|
reader.readAsText(current_file);
|
|
|
|
}
|
2013-01-19 15:37:39 +04:00
|
|
|
}
|
2013-01-19 22:40:44 +04:00
|
|
|
};
|
2012-04-26 13:38:55 +04:00
|
|
|
|
2012-04-28 15:10:29 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/***************************
|
|
|
|
**** On document ready ***
|
|
|
|
****************************/
|
2012-05-06 21:24:46 +04:00
|
|
|
|
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
$(function () {
|
2012-04-26 13:38:55 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/**
|
2012-04-28 19:11:32 +04:00
|
|
|
On the create paste page:
|
|
|
|
On click on the send button, compress and encrypt data before
|
|
|
|
posting it using ajax. Then redirect to the address of the
|
|
|
|
newly created paste, adding the key in the hash.
|
|
|
|
*/
|
2013-01-19 22:40:44 +04:00
|
|
|
$('.btn-primary').live("click", function (e) {
|
2012-04-26 13:38:55 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
e.preventDefault();
|
|
|
|
var paste = $('textarea').val();
|
2012-04-26 13:38:55 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
if (paste.trim()) {
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
var $form = $('input, textarea, select, button').prop('disabled', true);
|
2012-05-06 21:24:46 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
// set up progress bar
|
|
|
|
var bar = zerobin.progressBar('form.well .progress');
|
|
|
|
bar.container.show();
|
|
|
|
bar.set('Converting paste to bits...', '25%');
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* Encode, compress, encrypt and send the paste then redirect the user
|
2012-04-29 21:50:39 +04:00
|
|
|
to the new paste. We ensure a loading animation is updated
|
|
|
|
during the process by passing callbacks.
|
|
|
|
*/
|
2013-01-19 22:40:44 +04:00
|
|
|
try {
|
|
|
|
|
|
|
|
var expiration = $('#expiration').val();
|
2014-06-20 11:16:17 +04:00
|
|
|
var key = zerobin.makeKey(256);
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
zerobin.encrypt(key, paste,
|
|
|
|
|
|
|
|
mkcb(bar.set, 'Encoding to base64...', '45%'),
|
|
|
|
mkcb(bar.set, 'Compressing...', '65%'),
|
|
|
|
mkcb(bar.set, 'Encrypting...', '85%'),
|
|
|
|
|
|
|
|
/* This block deal with sending the data, redirection or error handling */
|
|
|
|
function (content) {
|
|
|
|
|
|
|
|
bar.set('Sending...', '95%');
|
|
|
|
var data = {
|
|
|
|
content: content,
|
|
|
|
expiration: expiration
|
|
|
|
};
|
|
|
|
var sizebytes = zerobin.count(JSON.stringify(data));
|
|
|
|
var oversized = sizebytes > zerobin.max_size; // 100kb - the others header information
|
|
|
|
var readableFsize = Math.round(sizebytes / 1024);
|
|
|
|
var readableMaxsize = Math.round(zerobin.max_size / 1024);
|
|
|
|
|
|
|
|
if (oversized) {
|
|
|
|
bar.container.hide();
|
|
|
|
$form.prop('disabled', false);
|
|
|
|
zerobin.message('error', ('The encrypted file was <strong class="file-size">' + readableFsize +
|
|
|
|
'</strong>KB. You have reached the maximum size limit of ' + readableMaxsize + 'KB.'),
|
|
|
|
'Warning!', true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$.post('/paste/create', data)
|
|
|
|
.error(function (error) {
|
2012-04-30 00:15:11 +04:00
|
|
|
$form.prop('disabled', false);
|
2012-05-06 21:24:46 +04:00
|
|
|
bar.container.hide();
|
2012-04-30 00:15:11 +04:00
|
|
|
zerobin.message(
|
|
|
|
'error',
|
|
|
|
'Paste could not be saved. Please try again later.',
|
2013-01-19 22:40:44 +04:00
|
|
|
'Error');
|
2012-04-30 00:15:11 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
})
|
|
|
|
.success(function (data) {
|
2012-05-06 21:24:46 +04:00
|
|
|
bar.set('Redirecting to new paste...', '100%');
|
2012-04-30 00:20:48 +04:00
|
|
|
|
2012-05-12 12:15:09 +04:00
|
|
|
if (data.status === 'error') {
|
|
|
|
zerobin.message('error', data.message, 'Error');
|
2012-04-30 00:20:48 +04:00
|
|
|
$form.prop('disabled', false);
|
2012-05-06 21:24:46 +04:00
|
|
|
bar.container.hide();
|
2012-04-30 00:20:48 +04:00
|
|
|
} else {
|
2012-05-12 12:15:09 +04:00
|
|
|
var paste_url = '/paste/' + data.paste + '#' + key;
|
2013-01-19 22:40:44 +04:00
|
|
|
if (zerobin.support.localStorage) {
|
2012-05-16 20:44:56 +04:00
|
|
|
zerobin.storePaste(paste_url);
|
|
|
|
}
|
2012-04-30 00:20:48 +04:00
|
|
|
window.location = (paste_url);
|
|
|
|
}
|
2013-01-19 22:40:44 +04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
$form.prop('disabled', false);
|
|
|
|
bar.container.hide();
|
|
|
|
zerobin.message('error', 'Paste could not be encrypted. Aborting.',
|
|
|
|
'Error');
|
2012-04-29 21:50:39 +04:00
|
|
|
}
|
2013-01-19 22:40:44 +04:00
|
|
|
}
|
|
|
|
});
|
2012-04-24 22:15:38 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/**
|
2012-04-29 21:50:39 +04:00
|
|
|
DECRYPTION:
|
|
|
|
On the display paste page, decrypt and decompress the paste content,
|
|
|
|
add syntax coloration then setup the copy to clipboard button.
|
2012-05-06 21:24:46 +04:00
|
|
|
Also calculate and set the paste visual hash.
|
2012-04-28 19:11:32 +04:00
|
|
|
*/
|
2013-01-19 22:40:44 +04:00
|
|
|
var content = $('#paste-content').text().trim();
|
|
|
|
var key = zerobin.getPasteKey();
|
|
|
|
var error = false;
|
2012-05-22 21:10:54 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
if (content && key) {
|
2012-04-28 21:57:18 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* Load the lib for visual canvas, create one from the paste id and
|
2012-05-06 21:24:46 +04:00
|
|
|
insert it */
|
2013-01-19 22:40:44 +04:00
|
|
|
$.getScript("/static/js/vizhash.min.js").done(function (script, textStatus) {
|
|
|
|
if (vizhash.supportCanvas) {
|
|
|
|
var vhash = vizhash.canvasHash(zerobin.getPasteId(), 24, 24);
|
|
|
|
$('<a class="vhash" href="#"></a>').click(function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
if (confirm("This picture is unique to your paste so you can identify" +
|
|
|
|
" it quickly. \n\n Do you want to know more about this?")) {
|
|
|
|
window.open("http://is.gd/IJaMRG", "_blank");
|
|
|
|
}
|
|
|
|
}).prependTo('.lnk-option').append(vhash.canvas);
|
2012-05-06 21:24:46 +04:00
|
|
|
}
|
2013-01-19 22:40:44 +04:00
|
|
|
});
|
2012-05-06 21:24:46 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
var $form = $('input, textarea, select, button').prop('disabled', true);
|
2012-05-06 21:24:46 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
var bar = zerobin.progressBar('.well form .progress');
|
|
|
|
bar.container.show();
|
|
|
|
bar.set('Decrypting paste...', '25%');
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
zerobin.decrypt(key, content,
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* On error*/
|
|
|
|
function () {
|
|
|
|
bar.container.hide();
|
|
|
|
zerobin.message('error', 'Could not decrypt data (Wrong key ?)', 'Error');
|
|
|
|
},
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* Update progress bar */
|
|
|
|
mkcb(bar.set, 'Decompressing...', '45%'),
|
|
|
|
mkcb(bar.set, 'Base64 decoding...', '65%'),
|
|
|
|
mkcb(bar.set, 'From bits to string...', '85%'),
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* When done */
|
|
|
|
function (content) {
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* Decrypted content goes back to initial container*/
|
|
|
|
$('#paste-content').text(content);
|
2012-04-28 21:57:18 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
if (content.indexOf('data:image') == 0) {
|
|
|
|
// Display Image
|
|
|
|
$('#paste-content').hide();
|
|
|
|
var img = $('<img/>');
|
|
|
|
$(img).attr('src', content);
|
|
|
|
$(img).css('max-width', '742px');
|
|
|
|
$('#paste-content').after(img);
|
2012-05-06 21:24:46 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
// Display Download button
|
|
|
|
$('.btn-clone').hide();
|
2012-05-06 21:24:46 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
var button = $('<a/>').attr('href', content);
|
|
|
|
$(button).attr('download', '0bin_' + document.location.pathname.split('/').pop());
|
|
|
|
$(button).addClass('btn');
|
|
|
|
$(button).html('<i class="icon-download"></i> Download');
|
|
|
|
$('.btn-clone').after(button);
|
|
|
|
|
|
|
|
}
|
|
|
|
bar.set('Code coloration...', '95%');
|
|
|
|
|
|
|
|
/* Add a continuation to let the UI redraw */
|
|
|
|
setTimeout(function () {
|
|
|
|
|
|
|
|
/* Setup flash clipboard button */
|
|
|
|
ZeroClipboard.setMoviePath('/static/js/ZeroClipboard.swf');
|
|
|
|
|
|
|
|
var clip = new ZeroClipboard.Client();
|
|
|
|
|
|
|
|
// Callback to reposition the clibpboad flash animation overlay
|
|
|
|
var reposition = function () {
|
|
|
|
clip.reposition();
|
|
|
|
};
|
|
|
|
|
|
|
|
clip.addEventListener('mouseup', function () {
|
|
|
|
$('#clip-button').text('Copying paste...');
|
|
|
|
clip.setText(zerobin.getPasteContent());
|
|
|
|
});
|
|
|
|
clip.addEventListener('complete', function () {
|
|
|
|
$('#clip-button').text('Copy to clipboard');
|
|
|
|
zerobin.message('info', 'The paste is now in your clipboard', '',
|
|
|
|
true, reposition);
|
|
|
|
});
|
|
|
|
clip.glue('clip-button');
|
|
|
|
|
|
|
|
window.onresize = reposition;
|
|
|
|
|
|
|
|
|
|
|
|
/* Setup link to get the paste short url*/
|
|
|
|
$('#short-url').click(function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
$('#short-url').text('Loading short url...');
|
|
|
|
zerobin.getTinyURL(window.location.toString(), function (tinyurl) {
|
|
|
|
clip.setText(tinyurl);
|
|
|
|
$('#copy-success').hide();
|
|
|
|
zerobin.message('success',
|
|
|
|
'<a href="' + tinyurl + '">' + tinyurl + '</a>',
|
|
|
|
'Short url', true, reposition);
|
|
|
|
$('#short-url').text('Get short url');
|
|
|
|
});
|
2012-05-01 20:56:55 +04:00
|
|
|
});
|
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* Remap the message close handler to include the clipboard
|
2012-05-01 21:17:27 +04:00
|
|
|
flash reposition */
|
2013-01-19 22:40:44 +04:00
|
|
|
$(".close").die().live('click', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
$(this).parent().fadeOut(reposition);
|
|
|
|
});
|
2012-05-01 21:17:27 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/** Syntaxic coloration */
|
|
|
|
|
|
|
|
if (zerobin.isCode(content) > 100) {
|
|
|
|
$('#paste-content').addClass('linenums');
|
|
|
|
prettyPrint();
|
|
|
|
} else {
|
|
|
|
if (content.indexOf('data:image') != 0) {
|
|
|
|
zerobin.message('info',
|
|
|
|
"The paste did not seem to be code, so it " +
|
|
|
|
"was not colorized. " +
|
|
|
|
"<a id='force-coloration' href='#'>Force coloration</a>",
|
|
|
|
'', false, reposition);
|
|
|
|
}
|
2013-01-19 20:05:37 +04:00
|
|
|
}
|
2012-04-28 21:57:18 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* Class to switch to paste content style with coloration done */
|
|
|
|
$('#paste-content').addClass('done');
|
2012-05-06 15:54:57 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* Display result */
|
|
|
|
bar.set('Done', '100%');
|
|
|
|
bar.container.hide();
|
2012-05-06 21:24:46 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
$form.prop('disabled', false);
|
|
|
|
content = '';
|
2012-05-06 21:24:46 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
}, 250);
|
2012-04-28 21:57:18 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
});
|
2012-04-29 21:50:39 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
} /* End of "DECRYPTION" */
|
2012-04-28 21:57:18 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* Synchronize expiration select boxes value */
|
|
|
|
$('.paste-option select').live('change', function () {
|
|
|
|
$('.paste-option select').val($(this).val());
|
|
|
|
});
|
2012-04-28 14:36:03 +04:00
|
|
|
|
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* Resize Textarea according to content */
|
|
|
|
$('#content').elastic();
|
2012-04-28 14:36:03 +04:00
|
|
|
|
2012-04-28 15:25:43 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* Display bottom paste option buttons when needed */
|
|
|
|
$('#content').live('keyup change', function () {
|
|
|
|
if ($('#content').height() < 400) {
|
|
|
|
$('.paste-option.down').remove();
|
|
|
|
} else {
|
2012-05-06 21:24:46 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
if ($('.paste-option').length === 1) {
|
|
|
|
$('.paste-option').clone().addClass('down').appendTo('form.well');
|
|
|
|
}
|
|
|
|
}
|
2012-04-30 00:15:11 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
});
|
2012-04-28 17:04:24 +04:00
|
|
|
|
2012-05-06 21:24:46 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* Display previous pastes */
|
|
|
|
if (zerobin.support.localStorage) {
|
2012-04-28 21:58:30 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
var $container = $('.previous-pastes'),
|
|
|
|
pastes = zerobin.getPreviousPastes();
|
2012-04-28 21:55:00 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
if (pastes.length) {
|
2012-04-28 21:55:00 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
$.getScript("/static/js/vizhash.min.js").done(function (script, textStatus) {
|
2012-04-29 19:36:26 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
$container.find('.item').remove();
|
|
|
|
$.each(zerobin.getPreviousPastes(), function (i, paste) {
|
2012-04-30 00:15:11 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
var $li = $('<li class="item"></li>').appendTo($container);
|
|
|
|
var $link = $('<a></a>').attr('href', paste.link)
|
|
|
|
.text(paste.prefix + paste.displayDate)
|
|
|
|
.appendTo($li);
|
2012-04-29 19:36:26 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
if (vizhash.supportCanvas) {
|
|
|
|
var pasteId = zerobin.getPasteId(paste.link);
|
|
|
|
var vhash = vizhash.canvasHash(pasteId, 24, 24).canvas;
|
|
|
|
$link.prepend($(vhash).addClass('vhash'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// hightlite the current link and make sure clicking the link
|
|
|
|
// does redirect to the page
|
|
|
|
if (paste.link.replace(/#[^#]+/, '') === window.location.pathname) {
|
|
|
|
$li.addClass('active');
|
|
|
|
$link.click(function () {
|
|
|
|
window.location = $link.attr('href');
|
|
|
|
window.location.reload();
|
|
|
|
});
|
|
|
|
}
|
2012-04-29 19:36:26 +04:00
|
|
|
|
2012-05-22 21:10:54 +04:00
|
|
|
});
|
2012-05-06 21:24:46 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
});
|
2012-05-06 21:24:46 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
}
|
2012-05-06 21:24:46 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
}
|
2012-04-29 19:36:26 +04:00
|
|
|
|
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* Event handler for "clone paste" button */
|
|
|
|
$('.btn-clone').click(function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
$('.submit-form').show();
|
|
|
|
$('.paste-form').hide();
|
|
|
|
$('#content').val(zerobin.getPasteContent()).trigger('change');
|
|
|
|
});
|
2012-04-28 21:58:30 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
$('.clone .btn-danger').click(function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
$('.submit-form').hide();
|
|
|
|
$('.paste-form').show();
|
|
|
|
});
|
2012-04-28 21:55:00 +04:00
|
|
|
|
|
|
|
|
2012-04-29 19:36:26 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* Upload file using HTML5 File API */
|
|
|
|
if (zerobin.support.fileUpload) {
|
2013-01-19 14:31:03 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
var $buttonOverlay = $('#file-upload');
|
|
|
|
var $button = $('.btn-upload');
|
2012-05-06 21:24:46 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
try {
|
|
|
|
$button.val('Uploading...');
|
|
|
|
$button.prop('disabled', true);
|
|
|
|
$buttonOverlay.change(function () {
|
|
|
|
zerobin.upload(this.files);
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
zerobin.message('error', 'Could no upload the file', 'Error');
|
|
|
|
$button.val('Upload File');
|
|
|
|
$button.prop('disabled', false);
|
|
|
|
}
|
2012-04-29 19:36:26 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
$button.prop('disabled', false);
|
|
|
|
$button.val('Upload File');
|
|
|
|
$buttonOverlay.mouseover(mkcb($(this).css, 'cursor', 'pointer'));
|
2012-04-29 19:36:26 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
// Implements drag & drop upload
|
|
|
|
$('#content').bind('drop', zerobin.handleDrop);
|
|
|
|
$('#content').bind('dragover', zerobin.handleDragOver);
|
|
|
|
$('#content').bind('dragleave', zerobin.handleDragLeave);
|
2013-01-19 14:31:03 +04:00
|
|
|
|
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
}
|
2012-04-29 19:36:26 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* Alerts */
|
2012-04-29 22:10:04 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
$(".close").live('click', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
$(this).parent().fadeOut();
|
|
|
|
});
|
2012-04-28 21:55:00 +04:00
|
|
|
|
2012-04-28 17:04:24 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* Parse obfuscaded emails and make them usable */
|
|
|
|
$('.email-link').each(function (i, elem) {
|
|
|
|
var $obfuscatedEmail = $(this);
|
|
|
|
var address = $obfuscatedEmail.attr('title').replace('__AT__', '@');
|
|
|
|
var text = $obfuscatedEmail.text().replace('__AT__', '@');
|
|
|
|
var $plainTextEmail = $('<a href="mailto:' + address + '">' + text + '</a>');
|
|
|
|
$obfuscatedEmail.replaceWith($plainTextEmail);
|
2012-05-08 14:52:17 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
});
|
2012-05-08 14:52:17 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* Show the page using javascript. Non js enabled browser will see an
|
2012-05-22 19:40:57 +04:00
|
|
|
error message */
|
2013-01-19 22:40:44 +04:00
|
|
|
$('#wrap-content').each(function (i, elem) {
|
|
|
|
$(elem).show();
|
|
|
|
});
|
2012-05-22 19:40:57 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* Remove expired pasted from history */
|
|
|
|
if (zerobin.support.history && zerobin.paste_not_found) {
|
|
|
|
var paste_id = zerobin.getPasteId();
|
|
|
|
var keys = zerobin.getLocalStorageKeys();
|
|
|
|
$.each(keys, function (i, key) {
|
|
|
|
if (localStorage[key].indexOf(paste_id) !== -1) {
|
|
|
|
localStorage.removeItem(key);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2012-05-08 14:52:17 +04:00
|
|
|
|
2012-05-22 21:10:54 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
/* Force text coloration when clickin on link */
|
|
|
|
$("#force-coloration").live("click", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
$('#paste-content').addClass('linenums');
|
|
|
|
$(this).die(e).text('Applying coloration');
|
|
|
|
prettyPrint();
|
|
|
|
$(this).remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
/* Send the paste by email */
|
2013-01-24 12:53:04 +04:00
|
|
|
$('#email-link').click(function() {
|
|
|
|
zerobin.getTinyURL(window.location.toString(), function(tinyurl) {
|
2013-01-31 15:05:48 +04:00
|
|
|
document.location.href= 'mailto:friend@example.com?body=' + tinyurl;
|
2013-01-24 12:53:04 +04:00
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
2012-05-23 18:20:46 +04:00
|
|
|
|
2012-05-22 21:10:54 +04:00
|
|
|
|
2013-01-19 22:40:44 +04:00
|
|
|
}); /* End of "document ready" jquery callback */
|
2012-04-28 17:04:24 +04:00
|
|
|
|
2012-05-20 05:22:20 +04:00
|
|
|
})(); /* End of self executing function */
|