From a3bb45a419aadbf133c8b23962b13c1d45464feb Mon Sep 17 00:00:00 2001 From: max Date: Sat, 28 Apr 2012 20:04:24 +0700 Subject: [PATCH] added previous pastes saving in localstorage --- static/css/style.css | 16 ++++++------- static/js/behavior.js | 54 +++++++++++++++++++++++++++++++++++++++---- views/base.tpl | 5 ++-- 3 files changed, 60 insertions(+), 15 deletions(-) diff --git a/static/css/style.css b/static/css/style.css index b85dee8..e974be2 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -68,12 +68,13 @@ p { margin: 0 0 20px; } +.nav-header { + font-size: 10px; +} .form-options li{ - -float: left; -list-style-type: none; - + float: left; + list-style-type: none; } form textarea { @@ -106,13 +107,13 @@ form { } .btn-primary { -position:relative; -top:-4px; + position:relative; + top:-4px; } .linenums{ -padding:1em 50px; + padding:1em 50px; } ol.linenums li { @@ -122,7 +123,6 @@ ol.linenums li { ol.linenums span:first-child { border-left: solid 1px #999; padding-left:1em; - } li.L0, li.L1, li.L2, li.L3, li.L4, diff --git a/static/js/behavior.js b/static/js/behavior.js index ad43da4..048edba 100644 --- a/static/js/behavior.js +++ b/static/js/behavior.js @@ -26,6 +26,31 @@ zerobin = { if(this.width + this.height != 2){no()} else {yes()} } data.src = "data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs="; + }, + support_localstorage: function(){ + if (localStorage){ + return true; + }else{ + return false; + } + }, + store_paste: function(url){ + if (zerobin.support_localstorage){ + localStorage.setItem(localStorage.length, url); + } + }, + get_pastes: function(){ + if (zerobin.support_localstorage){ + var val = ''; + for (i=0; i<=localStorage.length-1; i++) + { + key = localStorage.key(i); + val = val + '
  • paste ' + (i+1) + '
  • '; + } + return val; + }else{ + return 'Sorry your browser does not support LocalStorage, We cannot display your previous pastes.'; + } } }; @@ -50,7 +75,9 @@ $('button[type=submit]').click(function(e){ alert('Paste could not be saved. Please try again later.'); }) .success(function(data) { - window.location = ('/paste/' + data['paste'] + '#' + key); + var paste_url = '/paste/' + data['paste'] + '#' + key; + window.location = (paste_url); + zerobin.store_paste(paste_url); }); } @@ -81,7 +108,7 @@ $('#content').elastic(); /* Display bottom paste option buttons when needed */ if($('#content').height() < 600 ){ $('.paste-option.bottom').remove(); -}; +} $('#content').live('keyup change', function(){ if($('#content').height() < 600 ){ $('.paste-option.down').remove(); @@ -90,8 +117,27 @@ $('#content').live('keyup change', function(){ if ($('.paste-option').length == 1) { $('.paste-option').clone().addClass('down').appendTo('form.well'); } - }; + } +}); + +/* Display previous pastes */ +$('.previous-pastes .items').html(zerobin.get_pastes()); + + }); -}); \ No newline at end of file + + + + + + + + + + + + + + diff --git a/views/base.tpl b/views/base.tpl index bb3aea9..8d8dcbc 100644 --- a/views/base.tpl +++ b/views/base.tpl @@ -52,10 +52,9 @@