diff --git a/src/paste.py b/src/paste.py index b7ecf63..f4d6f40 100644 --- a/src/paste.py +++ b/src/paste.py @@ -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') diff --git a/static/css/style.css b/static/css/style.css index 1c1c166..c4e2686 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -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; } diff --git a/static/js/behavior.js b/static/js/behavior.js index 1bee0ad..1c72cc1 100644 --- a/static/js/behavior.js +++ b/static/js/behavior.js @@ -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: ' + tinyurk + '') + .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(); diff --git a/views/paste.tpl b/views/paste.tpl index eb43dae..cba527f 100644 --- a/views/paste.tpl +++ b/views/paste.tpl @@ -17,9 +17,13 @@ The paste is now in your clipboad +
+

+ Get short url | Copy To Clipboard