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:
parent
fa5797db2d
commit
a76e2e9a6f
@ -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
|
@ -109,6 +109,10 @@ h4#pixels-total {
|
|||||||
margin-top: 40px;
|
margin-top: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.alert .title {
|
||||||
|
display:block;
|
||||||
|
}
|
||||||
|
|
||||||
/* Home */
|
/* Home */
|
||||||
|
|
||||||
.btn-group {
|
.btn-group {
|
||||||
@ -143,10 +147,6 @@ input.hide-upload {
|
|||||||
height: 49px;
|
height: 49px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.max-size-reached {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Paste Page */
|
/* Paste Page */
|
||||||
|
|
||||||
.items {
|
.items {
|
||||||
@ -157,8 +157,6 @@ input.hide-upload {
|
|||||||
background-color: white;
|
background-color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
#copy-success,
|
|
||||||
#short-url-success,
|
|
||||||
.submit-form {
|
.submit-form {
|
||||||
display:none;
|
display:none;
|
||||||
}
|
}
|
||||||
|
@ -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.
|
||||||
@ -223,6 +223,19 @@ $.ajaxSetup({ cache: true });
|
|||||||
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');
|
||||||
|
|
||||||
@ -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();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
|
||||||
@ -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>
|
||||||
|
@ -1,9 +1,3 @@
|
|||||||
<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" >
|
||||||
@ -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>
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
%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>
|
||||||
|
<strong class="title">Ok!</strong>
|
||||||
|
<span class="message">
|
||||||
This paste will be deleted the next time it is read.
|
This paste will be deleted the next time it is read.
|
||||||
</div>
|
</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">
|
||||||
|
Loading…
Reference in New Issue
Block a user