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

Added get short url

This commit is contained in:
sam 2012-04-29 02:13:32 +07:00
parent 59f7b9bb56
commit 572a907dc9
4 changed files with 41 additions and 11 deletions

View File

@ -153,7 +153,7 @@ class Paste(object):
if self.expiration == "burn_after_reading":
self.expiration = self.expiration + '#%s' % datetime.now()
# writethe paste
# write the paste
with open(self.path, 'w') as f:
f.write(unicode(self.expiration) + '\n')
f.write(self.content + '\n')

View File

@ -41,7 +41,7 @@ body {
.paste-option {
float:right;
}
select {
width: 135px;
@ -152,8 +152,8 @@ ol.linenums span:first-child {
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;
list-style-type: decimal;
background: inherit;
}
#clip-container div:hover,
@ -162,7 +162,7 @@ li.L5, li.L6, li.L7, li.L8, li.L9
cursor:pointer;
}
#copy-success {
#copy-success, #short-url-success {
display:none;
}

View File

@ -31,6 +31,18 @@ zerobin = {
if (s<10) {s = "0" + s}
return h+":"+m+":"+s;
},
/** Get a tinyurl using JSONP */
getTinyURL: function(longURL, success) {
callback = 'zerobin_tiny_url_callback';
window[callback] = function(response){
success(response.tinyurl);
delete window[callback];
};
var api = 'http://json-tinyurl.appspot.com/?url=';
$.getJSON(api + encodeURIComponent(longURL) + '&callback=' + callback);
},
support_localstorage: function(){
if (localStorage){
return true;
@ -123,17 +135,31 @@ if (content && key) {
if (!error) {
ZeroClipboard.setMoviePath('/static/js/ZeroClipboard.swf' );
var clip = new ZeroClipboard.Client();
$('#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();
$('#short-url-success')
.html('Short url: <a href="' + tinyurk + '">' + tinyurk + '</a>')
.show('fadeUp');
$('#short-url').text('Get short url');
});
});
prettyPrint();
/* Setup flash clipboard button */
ZeroClipboard.setMoviePath('/static/js/ZeroClipboard.swf' );
var clip = new ZeroClipboard.Client();
clip.addEventListener('onMouseUp', function(){
clip.setText($('#paste-content').text());
});
clip.addEventListener('complete', function(){
$('#copy-success').show();
$('#copy-success').show('fadeUp');
});
clip.addEventListener('onLoad', function(){
});
@ -169,15 +195,15 @@ $('#content').live('keyup change', function(){
/* Display previous pastes */
$('.previous-pastes .items').html(zerobin.get_pastes());
/* clone a paste */
$('.btn-clone').click(function(e){
e.preventDefault();
content_clone = '' ;
$("#paste-content li").each(function(index) {
content_clone = content_clone + $(this).text() + '\n';
$("#paste-content li").each(function(index) {
content_clone = content_clone + $(this).text() + '\n';
});
$('.submit-form').show();
$('.paste-form').remove();

View File

@ -17,9 +17,13 @@
The paste is now in your clipboad
</div>
<div id="short-url-success" class="alert alert-success"></div>
<div class="well">
<form action="/" method="get" accept-charset="utf-8">
<p>
<a id="short-url" href=""
target="_blank">Get short url</a> |
<span id="clip-container" style="position:relative">
<a id="clip-button">Copy To Clipboard</a>
</span>