1
0
mirror of https://github.com/Tygs/0bin.git synced 2023-08-10 21:13:00 +03:00

Merge pull request #17 from Natim/master

Display bin image file as image.
This commit is contained in:
sametmax 2013-01-31 02:25:40 -08:00
commit 0c1bcfdc87
9 changed files with 731 additions and 577 deletions

View File

@ -10,7 +10,7 @@
import os
import sys
import thread
import urlparse
from datetime import datetime, timedelta
# add project dir and libs dir to the PYTHON PATH to ensure they are
@ -48,22 +48,28 @@ def faq():
@app.route('/paste/create', method='POST')
def create_paste():
try:
body = urlparse.parse_qs(request.body.read(int(settings.MAX_SIZE * 1.1)))
except ValueError:
return {'status': 'error',
'message': u"Wrong data payload."}
try:
content = unicode(request.forms.get('content', ''), 'utf8')
except UnicodeDecodeError:
content = unicode(''.join(body['content']), 'utf8')
except (UnicodeDecodeError, KeyError):
return {'status': 'error',
'message': u"Encoding error: the paste couldn't be saved."}
if '{"iv":' not in content: # reject silently non encrypted content
return ''
return {'status': 'error',
'message': u"Wrong data payload."}
if content:
# check size of the paste. if more than settings return error without saving paste.
# prevent from unusual use of the system.
# need to be improved
# check size of the paste. if more than settings return error
# without saving paste. prevent from unusual use of the
# system. need to be improved
if len(content) < settings.MAX_SIZE:
expiration = request.forms.get('expiration', u'burn_after_reading')
expiration = body.get('expiration', [u'burn_after_reading'])[0]
paste = Paste(expiration=expiration, content=content)
paste.save()
@ -81,12 +87,12 @@ def create_paste():
GLOBAL_CONTEXT['pastes_count'] = Paste.get_pastes_count()
GLOBAL_CONTEXT['refresh_counter'] = now
return {'status': 'ok',
'paste': paste.uuid}
return {'status': 'error',
'message': u"Serveur error: the paste couldn't be saved. Please try later."}
'message': u"Serveur error: the paste couldn't be saved. "
u"Please try later."}
@app.route('/paste/:paste_id')
@ -105,7 +111,8 @@ def display_paste(paste_id):
# to the paste that happens during the paste creation
try:
keep_alive = paste.expiration.split('#')[1]
keep_alive = datetime.strptime(keep_alive, '%Y-%m-%d %H:%M:%S.%f')
keep_alive = datetime.strptime(keep_alive,
'%Y-%m-%d %H:%M:%S.%f')
keep_alive = now < keep_alive + timedelta(seconds=10)
except IndexError:
keep_alive = False
@ -136,8 +143,8 @@ def server_static(filename):
def get_app(debug=None, settings_file='', compressed_static=None):
"""
Return a tuple (settings, app) configured using passed parameters and/or
a setting file.
Return a tuple (settings, app) configured using passed
parameters and/or a setting file.
"""
if settings_file:
settings.update_with_file(os.path.abspath(settings_file))
@ -159,8 +166,8 @@ def get_app(debug=None, settings_file='', compressed_static=None):
@clize.clize(coerce={'debug': bool, 'compressed_static': bool})
def runserver(host='', port='', debug=None, user='',
group='', settings_file='', compressed_static=None, version=False):
def runserver(host='', port='', debug=None, user='', group='',
settings_file='', compressed_static=None, version=False):
settings, app = get_app(debug, settings_file, compressed_static)

View File

@ -384,3 +384,7 @@ canvas {
-webkit-background-clip: padding-box;
background-clip: padding-box;
}
#content.hover {
background-color: #eee;
}

View File

@ -4,4 +4,4 @@ article,aside,details,figcaption,figure,footer,header,hgroup,nav,section{display
/* Prettify */
.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee}
/* Custom */
.brand{font-size:38px!important;padding:0 55px 3px!important;text-shadow:0 1px 0 rgba(255,255,255,.1),0 0 30px rgba(255,255,255,.125);-webkit-transition:all .2s linear;-moz-transition:all .2s linear;-o-transition:all .2s linear;-ms-transition:all .2s linear;transition:all .2s linear}.brand span{font-size:48px;line-height:0}.brand em{display:inline;color:#d40202;font-size:27px}.about{line-height:13px;font-style:italic;text-align:right;padding-top:9px;margin-bottom:0!important}.center{text-align:center}.about span{font-size:10px}body{padding-top:60px;padding-bottom:40px}.sidebar-nav{padding:9px 0}select{width:135px}label{display:inline;margin-left:18px;font-style:italic;font-size:11px;color:#888}ul,ol{padding:0;margin:0}li{margin-left:-9px}p{margin:0 0 20px}.grey{color:#999}.nav-list{padding-right:0!important;font-size:12px}blockquote{width:630px;float:left}h4 p{float:left;font-size:80px;text-shadow:1px 3px 1px #DDD,0 0 4px #333;-webkit-transition:all .2s linear;-o-transition:all .2s linear;-ms-transition:all .2s linear;-moz-transition:all .2s linear;transition:all .2s linear;margin-right:7px;margin-top:3px}h4#pixels-total{position:relative;width:166px;float:right;margin:8px 0 0 0;padding:0 0 0 54px;font-size:1.1em;line-height:1.4;font-weight:normal;color:#777;-webkit-border-top-right-radius:6px;-webkit-border-top-left-radius:20px;-moz-border-top-right-radius:6px;-moz-border-top-left-radius:20px;border-top-right-radius:6px;border-top-left-radius:20px}.greetings{clear:both;margin:0 auto;text-align:center;margin-top:40px}.alert .title{display:block}.btn-group{float:left}html.file-upload p.file-upload{float:left;margin:22px 0 0 21px;display:none}html.file-upload p.file-upload{display:inherit}html.no-file-upload p.file-upload{display:none}input.btn-upload{position:relative;left:-6px;width:100px;z-index:1;margin-top:-13px}input.hide-upload{position:relative;left:-110px;-moz-opacity:0;filter:alpha(opacity=0);opacity:0;z-index:2;width:100px;margin-top:-20px;cursor:pointer;cursor:hand;height:49px}#paste-content{background-color:white;padding:1em}#paste-content.linenums{padding-left:0}.submit-form{display:none}.paste-option{float:right}a#clip-button.hover{cursor:pointer;text-decoration:underline}li.L0,li.L1,li.L2,li.L3,li.L4,li.L5,li.L6,li.L7,li.L8,li.L9{list-style-type:decimal;background:inherit}.prettyprint.linenums{-webkit-box-shadow:inset 40px 0 0 #fbfbfc,inset 41px 0 0 #ececf0;-moz-box-shadow:inset 40px 0 0 #fbfbfc,inset 41px 0 0 #ececf0;box-shadow:inset 40px 0 0 #fbfbfc,inset 41px 0 0 #ececf0}ol.linenums{margin:0 0 0 55px}ol.linenums li{color:#bebec5;line-height:18px;text-shadow:0 1px 0 #fff}.prettyprint{padding:8px;background-color:#f7f7f9;border:1px solid #e1e1e8}pre{font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,monospace,serif;line-height:21px;font-size:12px}.kwd{color:#66F}.pun,.opn,.clo{color:#0A0}.lit{color:#933}.com{color:#C0C}form{padding-bottom:3em!important;padding-right:17px}form textarea{overflow-y:auto;min-height:250px}button.btn,input[type="submit"].btn{margin-left:5px}.well{padding-bottom:40px;padding-right:17px}.legal{margin:0 auto;width:300px;text-align:center;margin-top:30px}.btn{margin-left:5px}.btn-primary,.btn-danger{position:relative;top:-4px}#alert-template{display:none}.progress{display:none}.progress .bar{width:25%;text-indent:10px;text-align:left}.lnk-option canvas{vertical-align:middle;margin-right:10px}.previous-pastes .item{margin-top:5px;vertical-align:middle;line-height:24px;padding-left:1em}li.item{margin-left:-13px;margin-right:-5px}.previous-pastes canvas{display:block;float:left;margin-right:5px}html.local-storage .no-local-storage{display:none}html.no-local-storage .local-storage{display:none}canvas{border:1px solid white}#wrap-content{display:none}.noscript{text-align:center;color:red;font-weight:bold}#faq dt{margin:2em 0 1em 0}#faq p{margin:1em}#force-coloration{text-decoration:underline}#expiration-tag{float:right;margin:1em;background:grey;color:white;font-size:.8em;padding:0 1ex;opacity:.5;filter:alpha(opacity=50);font-weight:bold;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;-moz-background-clip:padding;-webkit-background-clip:padding-box;background-clip:padding-box}
.brand{font-size:38px!important;padding:0 55px 3px!important;text-shadow:0 1px 0 rgba(255,255,255,.1),0 0 30px rgba(255,255,255,.125);-webkit-transition:all .2s linear;-moz-transition:all .2s linear;-o-transition:all .2s linear;-ms-transition:all .2s linear;transition:all .2s linear}.brand span{font-size:48px;line-height:0}.brand em{display:inline;color:#d40202;font-size:27px}.about{line-height:13px;font-style:italic;text-align:right;padding-top:9px;margin-bottom:0!important}.center{text-align:center}.about span{font-size:10px}body{padding-top:60px;padding-bottom:40px}.sidebar-nav{padding:9px 0}select{width:135px}label{display:inline;margin-left:18px;font-style:italic;font-size:11px;color:#888}ul,ol{padding:0;margin:0}li{margin-left:-9px}p{margin:0 0 20px}.grey{color:#999}.nav-list{padding-right:0!important;font-size:12px}blockquote{width:630px;float:left}h4 p{float:left;font-size:80px;text-shadow:1px 3px 1px #DDD,0 0 4px #333;-webkit-transition:all .2s linear;-o-transition:all .2s linear;-ms-transition:all .2s linear;-moz-transition:all .2s linear;transition:all .2s linear;margin-right:7px;margin-top:3px}h4#pixels-total{position:relative;width:166px;float:right;margin:8px 0 0 0;padding:0 0 0 54px;font-size:1.1em;line-height:1.4;font-weight:normal;color:#777;-webkit-border-top-right-radius:6px;-webkit-border-top-left-radius:20px;-moz-border-top-right-radius:6px;-moz-border-top-left-radius:20px;border-top-right-radius:6px;border-top-left-radius:20px}.greetings{clear:both;margin:0 auto;text-align:center;margin-top:40px}.alert .title{display:block}.btn-group{float:left}html.file-upload p.file-upload{float:left;margin:22px 0 0 21px;display:none}html.file-upload p.file-upload{display:inherit}html.no-file-upload p.file-upload{display:none}input.btn-upload{position:relative;left:-6px;width:100px;z-index:1;margin-top:-13px}input.hide-upload{position:relative;left:-110px;-moz-opacity:0;filter:alpha(opacity=0);opacity:0;z-index:2;width:100px;margin-top:-20px;cursor:pointer;cursor:hand;height:49px}#paste-content{background-color:white;padding:1em}#paste-content.linenums{padding-left:0}.submit-form{display:none}.paste-option{float:right}a#clip-button.hover{cursor:pointer;text-decoration:underline}li.L0,li.L1,li.L2,li.L3,li.L4,li.L5,li.L6,li.L7,li.L8,li.L9{list-style-type:decimal;background:inherit}.prettyprint.linenums{-webkit-box-shadow:inset 40px 0 0 #fbfbfc,inset 41px 0 0 #ececf0;-moz-box-shadow:inset 40px 0 0 #fbfbfc,inset 41px 0 0 #ececf0;box-shadow:inset 40px 0 0 #fbfbfc,inset 41px 0 0 #ececf0}ol.linenums{margin:0 0 0 55px}ol.linenums li{color:#bebec5;line-height:18px;text-shadow:0 1px 0 #fff}.prettyprint{padding:8px;background-color:#f7f7f9;border:1px solid #e1e1e8}pre{font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,monospace,serif;line-height:21px;font-size:12px}.kwd{color:#66F}.pun,.opn,.clo{color:#0A0}.lit{color:#933}.com{color:#C0C}form{padding-bottom:3em!important;padding-right:17px}form textarea{overflow-y:auto;min-height:250px}button.btn,input[type="submit"].btn{margin-left:5px}.well{padding-bottom:40px;padding-right:17px}.legal{margin:0 auto;width:300px;text-align:center;margin-top:30px}.btn{margin-left:5px}.btn-primary,.btn-danger{position:relative;top:-4px}#alert-template{display:none}.progress{display:none}.progress .bar{width:25%;text-indent:10px;text-align:left}.lnk-option canvas{vertical-align:middle;margin-right:10px}.previous-pastes .item{margin-top:5px;vertical-align:middle;line-height:24px;padding-left:1em}li.item{margin-left:-13px;margin-right:-5px}.previous-pastes canvas{display:block;float:left;margin-right:5px}html.local-storage .no-local-storage{display:none}html.no-local-storage .local-storage{display:none}canvas{border:1px solid white}#wrap-content{display:none}.noscript{text-align:center;color:red;font-weight:bold}#faq dt{margin:2em 0 1em 0}#faq p{margin:1em}#force-coloration{text-decoration:underline}#expiration-tag{float:right;margin:1em;background:grey;color:white;font-size:.8em;padding:0 1ex;opacity:.5;filter:alpha(opacity=50);font-weight:bold;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;-moz-background-clip:padding;-webkit-background-clip:padding-box;background-clip:padding-box}#content.hover{background-color:#eee}

View File

@ -1,11 +1,14 @@
/*global sjcl:true, jQuery:true, $:true, lzw:true, zerobin:true, ZeroClipboard:true, vizhash:true, prettyPrint:true, confirm:true */
;(function(){
;
(function () {
"use strict";
/* Start random number generator seeding ASAP */
sjcl.random.startCollectors();
/* Ensure jquery use cache for ajax requests */
$.ajaxSetup({ cache: true });
$.ajaxSetup({
cache: true
});
/** Create a function that create inline callbacks.
We use it to create callbacks for onliners with static arguments
@ -27,7 +30,7 @@ function mkcb(func){
/***************************
**** 0bin utilities ***
****************************/
***************************/
window.zerobin = {
@ -42,21 +45,37 @@ window.zerobin = {
setTimeout(function () {
content = sjcl.codec.utf8String.toBits(content);
if (toBase64Callback) {toBase64Callback();}
if (toBase64Callback) {
toBase64Callback();
}
setTimeout(function () {
content = sjcl.codec.base64.fromBits(content);
if (compressCallback) {compressCallback();}
if (compressCallback) {
compressCallback();
}
setTimeout(function () {
content = lzw.compress(content);
if (encryptCallback) {encryptCallback();}
// content = lzw.compress(content); // Create a bug with JPG
if (encryptCallback) {
encryptCallback();
}
setTimeout(function () {
try {
content = sjcl.encrypt(key, content);
if (doneCallback) {doneCallback(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.',
'Error');
}
if (doneCallback) {
doneCallback(content);
}
}, 250);
}, 250);
@ -79,34 +98,35 @@ window.zerobin = {
/* Decrypt */
setTimeout(function () {
try {
content = sjcl.decrypt(key, content);
if (uncompressCallback) {uncompressCallback();}
if (uncompressCallback) {
uncompressCallback();
}
/* Decompress */
setTimeout(function () {
try {
content = lzw.decompress(content);
if (fromBase64Callback) {fromBase64Callback();}
if (fromBase64Callback) {
fromBase64Callback();
}
/* From base 64 to bits */
setTimeout(function () {
try {
content = sjcl.codec.base64.toBits(content);
if (toStringCallback) {toStringCallback();}
if (toStringCallback) {
toStringCallback();
}
/* From bits to string */
setTimeout(function () {
try {
content = sjcl.codec.utf8String.fromBits(content);
if (doneCallback) {doneCallback(content);}
if (doneCallback) {
doneCallback(content);
}
} catch (err) {
errorCallback(err);
}
@ -140,8 +160,7 @@ window.zerobin = {
getFormatedDate: function (date) {
date = date || new Date();
return ((date.getMonth() +1 ) + '-' +
date.getDate() + '-' + date.getFullYear());
return ((date.getMonth() + 1) + '-' + date.getDate() + '-' + date.getFullYear());
},
getFormatedTime: function (date) {
@ -149,9 +168,15 @@ window.zerobin = {
var h = date.getHours(),
m = date.getMinutes(),
s = date.getSeconds();
if (h < 10) {h = "0" + h;}
if (m < 10) {m = "0" + m;}
if (s < 10) {s = "0" + s;}
if (h < 10) {
h = "0" + h;
}
if (m < 10) {
m = "0" + m;
}
if (s < 10) {
s = "0" + s;
}
return h + ":" + m + ":" + s;
},
@ -177,9 +202,18 @@ window.zerobin = {
/** Get a tinyurl using JSONP */
getTinyURL: function(longURL, success) {
var api = 'http://is.gd/create.php?format=json&url=';
$.getJSON(api + encodeURIComponent(longURL) + '&callback=?', function(data){
success(data.shorturl);
$.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){
console.log(data);
success(data.id);
});
},
@ -211,8 +245,7 @@ window.zerobin = {
storePaste: function (url, date) {
date = date || new Date();
date = (date.getFullYear() + '-' + (date.getMonth() + 1) + '-' +
date.getDate() + ' ' + zerobin.getFormatedTime(date));
date = (date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + zerobin.getFormatedTime(date));
var keys = zerobin.getLocalStorageKeys();
@ -241,8 +274,11 @@ window.zerobin = {
displayDate = pasteDateTime.split(' ')[1];
prefix = 'at ';
}
pastes.push({displayDate: displayDate, prefix: prefix,
link: localStorage.getItem(key)});
pastes.push({
displayDate: displayDate,
prefix: prefix,
link: localStorage.getItem(key)
});
});
return pastes;
@ -304,14 +340,19 @@ window.zerobin = {
message: function (type, message, title, flush, callback) {
$(window).scrollTop(0);
if (flush) {$('.alert-'+type).remove();}
if (flush) {
$('.alert-' + type).remove();
}
var $message = $('#alert-template').clone().attr('id', null)
.addClass('alert alert-' + type);
$('.message', $message).html(message);
if (title) {$('.title', $message).html(title);}
else {$('.title', $message).remove();}
if (title) {
$('.title', $message).html(title);
} else {
$('.title', $message).remove();
}
$message.prependTo($('#main')).show('fadeUp', callback);
},
@ -319,8 +360,13 @@ window.zerobin = {
/** 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);};
var bar = {
container: $container,
elem: $container.find('.bar')
};
bar.set = function (text, rate) {
bar.elem.text(text).css('width', rate);
};
return bar;
},
@ -351,6 +397,80 @@ window.zerobin = {
}
return total * 1000 / size;
},
// prevent defaults
ignoreDrag: function (e) {
e.originalEvent.stopPropagation();
e.originalEvent.preventDefault();
},
// Handle Drop
handleDrop: function (e) {
e.originalEvent.preventDefault();
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);
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);
}
}
};
@ -373,20 +493,7 @@ $('.btn-primary').live("click", function(e){
e.preventDefault();
var paste = $('textarea').val();
var sizebytes = zerobin.count($('#content').val());
var oversized = sizebytes > zerobin.max_size;
var readableFsize = Math.round(sizebytes / 1024);
var readableMaxsize = Math.round(zerobin.max_size / 1024);
if (oversized){
zerobin.message('error',
('Your file is <strong class="file-size">' + readableFsize +
'</strong>KB. You have reached the maximum size limit of ' +
readableMaxsize + 'KB.'),
'Warning!', true);
}
if (!oversized && paste.trim()) {
if (paste.trim()) {
var $form = $('input, textarea, select, button').prop('disabled', true);
@ -414,7 +521,23 @@ $('.btn-primary').live("click", function(e){
function (content) {
bar.set('Sending...', '95%');
var data = {content: content, expiration: expiration};
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) {
@ -423,8 +546,7 @@ $('.btn-primary').live("click", function(e){
zerobin.message(
'error',
'Paste could not be saved. Please try again later.',
'Error'
);
'Error');
})
.success(function (data) {
@ -442,8 +564,7 @@ $('.btn-primary').live("click", function(e){
window.location = (paste_url);
}
});
}
);
});
} catch (err) {
$form.prop('disabled', false);
bar.container.hide();
@ -451,7 +572,6 @@ $('.btn-primary').live("click", function(e){
'Error');
}
}
});
/**
@ -506,6 +626,24 @@ if (content && key) {
/* Decrypted content goes back to initial container*/
$('#paste-content').text(content);
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);
// Display Download button
$('.btn-clone').hide();
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 */
@ -517,7 +655,9 @@ if (content && key) {
var clip = new ZeroClipboard.Client();
// Callback to reposition the clibpboad flash animation overlay
var reposition = function(){clip.reposition();};
var reposition = function () {
clip.reposition();
};
clip.addEventListener('mouseup', function () {
$('#clip-button').text('Copying paste...');
@ -542,8 +682,7 @@ if (content && key) {
$('#copy-success').hide();
zerobin.message('success',
'<a href="' + tinyurl + '">' + tinyurl + '</a>',
'Short url', true, reposition
);
'Short url', true, reposition);
$('#short-url').text('Get short url');
});
});
@ -561,12 +700,14 @@ if (content && key) {
$('#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);
}
}
/* Class to switch to paste content style with coloration done */
$('#paste-content').addClass('done');
@ -580,8 +721,7 @@ if (content && key) {
}, 250);
}
);
});
} /* End of "DECRYPTION" */
@ -599,8 +739,7 @@ $('#content').elastic();
$('#content').live('keyup change', function () {
if ($('#content').height() < 400) {
$('.paste-option.down').remove();
}
else {
} else {
if ($('.paste-option').length === 1) {
$('.paste-option').clone().addClass('down').appendTo('form.well');
@ -668,26 +807,20 @@ $('.clone .btn-danger').click(function(e){
});
/* Upload file using HTML5 File API */
if (zerobin.support.fileUpload) {
var upload = function(files) {
var reader = new FileReader();
reader.onload = function(event) {
$('#content').val(event.target.result).trigger('change');
};
reader.readAsText(files[0]);
};
var $buttonOverlay = $('#file-upload');
var $button = $('.btn-upload');
try {
$button.val('Uploading...');
$button.prop('disabled', true);
$buttonOverlay.change(function(){upload(this.files);});
}
catch (e) {
$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);
@ -696,6 +829,13 @@ if (zerobin.support.fileUpload) {
$button.prop('disabled', false);
$button.val('Upload File');
$buttonOverlay.mouseover(mkcb($(this).css, 'cursor', 'pointer'));
// Implements drag & drop upload
$('#content').bind('drop', zerobin.handleDrop);
$('#content').bind('dragover', zerobin.handleDragOver);
$('#content').bind('dragleave', zerobin.handleDragLeave);
}
/* Alerts */
@ -745,9 +885,12 @@ $("#force-coloration").live("click", function(e) {
});
/* Send the paste by email */
var emailLink = 'mailto:friend@example.com?body=' + window.location;
$('#email-link').attr('href', emailLink);
$('#email-link').click(function() {
zerobin.getTinyURL(window.location.toString(), function(tinyurl) {
window.open('mailto:friend@example.com?body=' + tinyurl);
});
return false;
});
}); /* End of "document ready" jquery callback */

File diff suppressed because one or more lines are too long

View File

@ -132,7 +132,7 @@
%if settings.DISPLAY_COUNTER:
<h4 id="pixels-total" >
<p>ø</p>
<strong>{{ pastes_count }}</strong> </br>pastes øbinned
<strong>{{ pastes_count }}</strong> <br/>pastes øbinned
</h4>
%end

View File

@ -72,14 +72,14 @@
<button class="btn btn-danger">Cancel clone</button>
</p>
<p>
<div>
<div class="progress progress-striped active">
<div class="bar"></div>
</div>
<textarea rows="10" style="width:100%;"
class="input-xlarge"
id="content" name="content"></textarea>
</p>
</div>
</form>
</div>