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

Generic message system

This commit is contained in:
sam 2012-04-30 03:15:11 +07:00
parent fa5797db2d
commit a76e2e9a6f
6 changed files with 98 additions and 71 deletions

View File

@ -29,4 +29,4 @@ GROUP = None
# limit size of pasted text in bytes. Be carefull allowing too much size can slow down user's # limit size of pasted text in bytes. Be carefull allowing too much size can slow down user's
# browser # browser
MAX_SIZE = 500 * 1 MAX_SIZE = 500 * 1000

View File

@ -109,6 +109,10 @@ h4#pixels-total {
margin-top: 40px; margin-top: 40px;
} }
.alert .title {
display:block;
}
/* Home */ /* Home */
.btn-group { .btn-group {
@ -126,7 +130,7 @@ input.btn-upload {
left: -6px; left: -6px;
width: 100px; width: 100px;
z-index: 1; z-index: 1;
margin-top: -13px; margin-top: -13px;
} }
input.hide-upload { input.hide-upload {
@ -143,10 +147,6 @@ input.hide-upload {
height: 49px; height: 49px;
} }
.max-size-reached {
display: none;
}
/* Paste Page */ /* Paste Page */
.items { .items {
@ -157,15 +157,13 @@ input.hide-upload {
background-color: white; background-color: white;
} }
#copy-success,
#short-url-success,
.submit-form { .submit-form {
display:none; display:none;
} }
.paste-option { .paste-option {
float:right; float:right;
} }
a#clip-button.hover{ a#clip-button.hover{
cursor:pointer; cursor:pointer;
@ -189,7 +187,7 @@ li.L5, li.L6, li.L7, li.L8, li.L9
ol.linenums { ol.linenums {
margin: 0 0 0 55px; /* IE indents via margin-left */ margin: 0 0 0 55px; /* IE indents via margin-left */
} }
ol.linenums li { ol.linenums li {
color: #bebec5; color: #bebec5;
line-height: 18px; line-height: 18px;
text-shadow: 0 1px 0 #fff; text-shadow: 0 1px 0 #fff;

View File

@ -1,11 +1,11 @@
; ;
/* Start random number generator seeding ASAP *% /* Start random number generator seeding ASAP */
sjcl.random.startCollectors(); sjcl.random.startCollectors();
/* Ensure jquery use cache for ajax requests */ /* Ensure jquery use cache for ajax requests */
$.ajaxSetup({ cache: true }); $.ajaxSetup({ cache: true });
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.
@ -211,18 +211,31 @@ $.ajaxSetup({ cache: true });
}); });
return content_clone; return content_clone;
}, },
count: function(text, options) { count: function(text, options) {
// Set option defaults // Set option defaults
var crlf = /(\r?\n|\r)/g; var crlf = /(\r?\n|\r)/g;
var whitespace = /(\r?\n|\r|\s+)/g; var whitespace = /(\r?\n|\r|\s+)/g;
options = options || {}; options = options || {};
options.lineBreaks = options.lineBreaks || 1; options.lineBreaks = options.lineBreaks || 1;
var length = text.length, var length = text.length,
nonAscii = length - text.replace(/[\u0100-\uFFFF]/g, '').length, nonAscii = length - text.replace(/[\u0100-\uFFFF]/g, '').length,
lineBreaks = length - text.replace(crlf, '').length; lineBreaks = length - text.replace(crlf, '').length;
return length + nonAscii + Math.max(0, options.lineBreaks * (lineBreaks - 1)); return length + nonAscii + Math.max(0, options.lineBreaks * (lineBreaks - 1));
},
message: function(type, message, title, flush, callback) {
if (flush) {$('.alert-'+type).remove()}
$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()}
$message.prependTo($('#main')).show('fadeUp', callback);
} }
}; };
@ -242,14 +255,20 @@ $('button[type=submit]').live("click", function(e){
var sizebytes = zerobin.count($('#content').val(), { }); var sizebytes = zerobin.count($('#content').val(), { });
var oversized = sizebytes > zerobin.max_size; var oversized = sizebytes > zerobin.max_size;
var readable_fsize = Math.round(sizebytes/1024);
var readable_maxsize = Math.round(zerobin.max_size/1024)
if (oversized){ if (oversized){
$('.max-size-reached').show(); zerobin.message('error',
$('.file-size').text(Math.round(sizebytes/1024)); ('Your file is <strong class="file-size">' + readable_fsize +
'</strong>KB. You have reached the maximum size limit of ' +
readable_maxsize + 'KB.'),
'Warning!', true)
} }
if (!oversized && paste.trim()) { if (!oversized && paste.trim()) {
$('form.well p').hide(); $form = $('input, textarea, select, button').prop('disabled', true);
$form.prop('disabled', true);
$loading = $('form.well .progress').show(); $loading = $('form.well .progress').show();
var $loading = $('form.well .progress .bar') var $loading = $('form.well .progress .bar')
.css('width', '25%') .css('width', '25%')
@ -278,9 +297,14 @@ $('button[type=submit]').live("click", function(e){
$.post('/paste/create', data) $.post('/paste/create', data)
.error(function(error) { .error(function(error) {
$('form.well p').show(); $form.prop('disabled', false);
$loading.hide(); $loading.hide();
alert('Error: paste could not be saved. Please try again later.'); zerobin.message(
'error',
'Paste could not be saved. Please try again later.',
'Error'
);
}) })
.success(function(data) { .success(function(data) {
$loading.text('Redirecting to new paste...').css('width', '100%'); $loading.text('Redirecting to new paste...').css('width', '100%');
@ -291,15 +315,16 @@ $('button[type=submit]').live("click", function(e){
} }
); );
} catch (err) { } catch (err) {
$('form.well p').show(); $form.prop('disabled', false);
$loading.hide(); $loading.hide();
alert('Error: paste could not be encrypted. Aborting.'); zerobin.message('error', 'Paste could not be encrypted. Aborting.',
'Error');
} }
} }
}); });
** /**
DECRYPTION: DECRYPTION:
On the display paste page, decrypt and decompress the paste content, On the display paste page, decrypt and decompress the paste content,
add syntax coloration then setup the copy to clipboard button. add syntax coloration then setup the copy to clipboard button.
@ -318,7 +343,8 @@ if (content && key) {
/* On error*/ /* On error*/
function(){ function(){
$bar.hide(); $bar.hide();
alert('Could not decrypt data (Wrong key ?)'); zerobin.message('error', 'Could not decrypt data (Wrong key ?)',
'Error');
}, },
/* Update progress bar */ /* Update progress bar */
@ -345,9 +371,10 @@ if (content && key) {
zerobin.getTinyURL(window.location.toString(), function(tinyurl){ zerobin.getTinyURL(window.location.toString(), function(tinyurl){
clip.setText(tinyurl); clip.setText(tinyurl);
$('#copy-success').hide(); $('#copy-success').hide();
$('#short-url-success') zerobin.message('success',
.html('Short url: <a href="' + tinyurk + '">' + tinyurk + '</a>') '<a href="' + tinyurk + '">' + tinyurk + '</a>',
.show('fadeUp'); 'Short url'
)
$('#short-url').text('Get short url'); $('#short-url').text('Get short url');
}); });
}); });
@ -360,7 +387,8 @@ if (content && key) {
clip.setText(zerobin.getPasteContent()); clip.setText(zerobin.getPasteContent());
}); });
clip.addEventListener('complete', function(){ clip.addEventListener('complete', function(){
$('#copy-success').show('fadeUp', function(){clip.reposition()}); zerobin.message('info', 'The paste is now in your clipboard',
'', false, function(){clip.reposition()});
}); });
clip.glue('clip-button'); clip.glue('clip-button');
@ -400,7 +428,7 @@ $('#content').live('keyup change', function(){
$('.paste-option').clone().addClass('down').appendTo('form.well'); $('.paste-option').clone().addClass('down').appendTo('form.well');
} }
} }
}); });
/* Display previous pastes */ /* Display previous pastes */
@ -419,10 +447,10 @@ $('.btn-clone').click(function(e){
/* Upload file using HTML5 File API */ /* Upload file using HTML5 File API */
if (window.File && window.FileReader && window.FileList && window.Blob) { if (window.File && window.FileReader && window.FileList && window.Blob) {
$('.file-upload').show(); $('.file-upload').show();
} }
var file_upload = function(file) { var file_upload = function(file) {
var reader = new FileReader(); var reader = new FileReader();
@ -441,7 +469,7 @@ try {
}); });
} }
catch (e) { catch (e) {
alert(e); zerobin.message('error', 'Could no upload the file', 'Error');
} }
$('#file-upload').mouseover(function(){ $('#file-upload').mouseover(function(){
@ -451,7 +479,7 @@ $('#file-upload').mouseover(function(){
/* Alerts */ /* Alerts */
$(".close").click(function(){ $(".close").live('click', function(){
$(this).parent().fadeOut(); $(this).parent().fadeOut();
}); });

View File

@ -23,7 +23,7 @@
<script src="/static/js/jquery-1.7.2.min.js"></script> <script src="/static/js/jquery-1.7.2.min.js"></script>
<script src="/static/js/behavior.js"></script> <script src="/static/js/behavior.js"></script>
<script type="text/javascript"> <script type="text/javascript">
zerobin.max_size = {{ max_size }}; zerobin.max_size = {{ get('max_size', -1)}};
</script> </script>
</head> </head>
@ -63,7 +63,7 @@
</div><!--/.well --> </div><!--/.well -->
</div><!--/span--> </div><!--/span-->
<div class="span10"> <div id='main' class="span10">
%include %include
@ -84,7 +84,7 @@
<strong>41,017,923,819</strong> pastes øbinned <strong>41,017,923,819</strong> pastes øbinned
</h4> </h4>
</br> </br>
<p class="greetings span12"> <p class="greetings span12">
Based on an original idea from Based on an original idea from
<a href="http://sebsauvage.net/paste/">sebsauvage.net</a><br> <a href="http://sebsauvage.net/paste/">sebsauvage.net</a><br>
@ -114,5 +114,12 @@
--> -->
<p id="alert-template">
<a class="close" data-dismiss="alert" href="#">×</a>
<strong class="title"></strong>
<span class="message"></span>
</p>
</body> </body>
</html> </html>

View File

@ -1,13 +1,7 @@
<div class="alert alert-error max-size-reached">
<a class="close" data-dismiss="alert" href="#">×</a>
<strong>Warning!</strong><br>
Your file is <strong class="file-size"></strong>KB You have reached the maximum size limit of {{ max_size_kb }}KB.
</div>
<p class="file-upload"> <p class="file-upload">
<input type="button" class="btn btn-upload" value="Upload File"> <input type="button" class="btn btn-upload" value="Upload File">
<input type="file" class="hide-upload" id="file-upload" > <input type="file" class="hide-upload" id="file-upload" >
</p> </p>
<form class="well" method="post" action="/paste/create"> <form class="well" method="post" action="/paste/create">
<p class="paste-option"> <p class="paste-option">
@ -19,15 +13,15 @@
<option value="never">Never</option> <option value="never">Never</option>
</select> </select>
<button type="submit" class="btn btn-primary">Submit</button> <button type="submit" class="btn btn-primary">Submit</button>
</p>
<p> <p>
<p> <div class="progress progress-striped active">
<div class="bar"></div>
</div>
<textarea rows="10" style="width:100%;" <textarea rows="10" style="width:100%;"
class="input-xlarge" class="input-xlarge"
id="content" name="content"></textarea> id="content" name="content"></textarea>
</p> </p>
<div class="progress progress-striped active">
<div class="bar"></div>
</div>
</form> </form>

View File

@ -1,31 +1,31 @@
%if "burn_after_reading" in str(paste.expiration): %if "burn_after_reading" in str(paste.expiration):
%if keep_alive: %if keep_alive:
<div class="alert alert-info"> <p class="alert alert-info">
<strong>Ok!</strong> <a class="close" data-dismiss="alert" href="#">×</a>
This paste will be deleted the next time it is read. <strong class="title">Ok!</strong>
</div> <span class="message">
This paste will be deleted the next time it is read.
</span>
</p>
%else: %else:
<div class="alert"> <p class="alert">
<strong>Warning!</strong> <a class="close" data-dismiss="alert" href="#">×</a>
This paste has self-destructed. If you close this windows, there is not way <strong class="title">Warning!</strong>
to recover it. <span class="message">
</div> This paste has self-destructed. If you close this windows,
there is not way to recover it.
</span>
</p>
%end %end
%end %end
<div id="copy-success" class="alert alert-success">
The paste is now in your clipboad
</div>
<div id="short-url-success" class="alert alert-success"></div>
<div class="well paste-form"> <div class="well paste-form">
<form action="/" method="get" accept-charset="utf-8"> <form action="/" method="get" accept-charset="utf-8">
<p class="lnk-option"> <p class="lnk-option">
<a id="clip-button">Copy To Clipboard</a> <a id="clip-button">Copy To Clipboard</a>
| |
<a id="short-url" href="" <a id="short-url" href=""
target="_blank">Get short url</a> target="_blank">Get short url</a>
<span class="paste-option btn-group top"> <span class="paste-option btn-group top">
<button class="btn btn-clone"><i class="icon-camera"></i>&nbsp;Clone</button> <button class="btn btn-clone"><i class="icon-camera"></i>&nbsp;Clone</button>
<button class="btn">New Paste</button> <button class="btn">New Paste</button>