From a3bb45a419aadbf133c8b23962b13c1d45464feb Mon Sep 17 00:00:00 2001 From: max Date: Sat, 28 Apr 2012 20:04:24 +0700 Subject: [PATCH 1/3] 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 @@
    From 1fa7218c7d1ab2c1f0fb5660f0f43ad5b3b41d20 Mon Sep 17 00:00:00 2001 From: max Date: Sat, 28 Apr 2012 21:37:00 +0700 Subject: [PATCH 2/3] added previous pastes saving in localstorage --- static/css/style.css | 56 ++++++++++++++++++++++++------------------- static/js/behavior.js | 35 ++++++++++++++++++++++----- views/base.tpl | 2 +- 3 files changed, 62 insertions(+), 31 deletions(-) diff --git a/static/css/style.css b/static/css/style.css index f7da822..4633b57 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -11,27 +11,27 @@ text-shadow: 0 1px 0 rgba(255, 255, 255, .1), 0 0 30px rgba(255, 255, 255, .125) transition: all .2s linear; } + .brand span { -font-size: 48px; -line-height: 0; - + font-size: 48px; + line-height: 0; } -.brand em { -display: inline; -color: #D40202; -margin: 0px !important; -font-size: 27px; +.brand em { + display: inline; + color: #D40202; + margin: 0px !important; + font-size: 27px; } /* body & other stuff */ body { -padding-top: 60px; -padding-bottom: 40px; + padding-top: 60px; + padding-bottom: 40px; } .sidebar-nav { -padding: 9px 0; + padding: 9px 0; } .btn-group { @@ -43,7 +43,7 @@ padding: 9px 0; } #paste-content { -background-color:white; + background-color:white; } select { @@ -51,25 +51,33 @@ select { } label { - -display: inline; -margin-left: 18px; -font-style: italic; -font-size: 11px; -color: #888; + display: inline; + margin-left: 18px; + font-style: italic; + font-size: 11px; + color: #888; } ul, ol { -padding: 0; -margin: 0; + padding: 0; + margin: 0; } p { margin: 0 0 20px; } -.nav-header { - font-size: 10px; +.grey { + color: #999; +} + +.items { + text-align: center; +} + +.nav-list { + padding-right: 0px !important; + font-size: 12px; } .form-options li{ @@ -113,11 +121,11 @@ form { pre { -padding:1em 20px !important; + padding:1em 20px !important; } .linenums { -padding-left: 35px; + padding-left: 35px; } diff --git a/static/js/behavior.js b/static/js/behavior.js index 53bc0c7..2c8f668 100644 --- a/static/js/behavior.js +++ b/static/js/behavior.js @@ -27,6 +27,14 @@ zerobin = { } data.src = "data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs="; }, + get_date: function(){ + var date = new Date(); + return date.getDate()+"-"+(date.getMonth()+1)+"-"+date.getFullYear(); + }, + get_time: function(){ + var date = new Date(); + return date.getHours()+":"+date.getMinutes()+":"+date.getSeconds(); + }, support_localstorage: function(){ if (localStorage){ return true; @@ -36,18 +44,33 @@ zerobin = { }, store_paste: function(url){ if (zerobin.support_localstorage){ - localStorage.setItem(localStorage.length, url); + var date = new Date(); + var paste = zerobin.get_date()+" "+zerobin.get_time()+";"+url; + if (localStorage.length > 19) + void removeItem(localStorage.length); + localStorage.setItem(localStorage.length, paste); } }, get_pastes: function(){ - if (zerobin.support_localstorage){ - var val = ''; + if (zerobin.support_localstorage){ + var date = new Date(); + var pastes = ''; + var key = ''; + for (i=0; i<=localStorage.length-1; i++) { - key = localStorage.key(i); - val = val + '
  • paste ' + (i+1) + '
  • '; + key = localStorage.key(i); + if (localStorage.getItem(key).split(';')[0].split(' ')[0] == zerobin.get_date()){ + var display_date = localStorage.getItem(key).split(';')[0].split(' ')[1]; + }else{ + var display_date = zerobin.get_date(); + } + pastes = pastes + '
  • ' + display_date + '
  • '; } - return val; + if (!pastes){ + return 'Your previous pastes will be saved in your browser localStorage.'; + } + return pastes; }else{ return 'Sorry your browser does not support LocalStorage, We cannot display your previous pastes.'; } diff --git a/views/base.tpl b/views/base.tpl index 8d8dcbc..3d9309a 100644 --- a/views/base.tpl +++ b/views/base.tpl @@ -54,7 +54,7 @@
    From af3d088ea486160bed4b1ae2489cab8fd0c3cc80 Mon Sep 17 00:00:00 2001 From: max Date: Sat, 28 Apr 2012 21:53:02 +0700 Subject: [PATCH 3/3] added previous pastes saving in localstorage --- static/js/behavior.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/static/js/behavior.js b/static/js/behavior.js index 2c8f668..e4dcc50 100644 --- a/static/js/behavior.js +++ b/static/js/behavior.js @@ -33,7 +33,13 @@ zerobin = { }, get_time: function(){ var date = new Date(); - return date.getHours()+":"+date.getMinutes()+":"+date.getSeconds(); + var h=date.getHours(); + var m=date.getMinutes(); + var s=date.getSeconds(); + if (h<10) {h = "0" + h} + if (m<10) {m = "0" + m} + if (s<10) {s = "0" + s} + return h+":"+m+":"+s; }, support_localstorage: function(){ if (localStorage){ @@ -47,25 +53,22 @@ zerobin = { var date = new Date(); var paste = zerobin.get_date()+" "+zerobin.get_time()+";"+url; if (localStorage.length > 19) - void removeItem(localStorage.length); + void removeItem(0); localStorage.setItem(localStorage.length, paste); } }, get_pastes: function(){ - if (zerobin.support_localstorage){ - var date = new Date(); - var pastes = ''; - var key = ''; + if (zerobin.support_localstorage){ + var pastes = ''; - for (i=0; i<=localStorage.length-1; i++) - { - key = localStorage.key(i); - if (localStorage.getItem(key).split(';')[0].split(' ')[0] == zerobin.get_date()){ - var display_date = localStorage.getItem(key).split(';')[0].split(' ')[1]; + for (i=localStorage.length-1; i>=0; i--) + { + if (localStorage.getItem(i).split(';')[0].split(' ')[0] == zerobin.get_date()){ + var display_date = localStorage.getItem(i).split(';')[0].split(' ')[1]; }else{ var display_date = zerobin.get_date(); } - pastes = pastes + '
  • ' + display_date + '
  • '; + pastes = pastes + '
  • ' + display_date + '
  • '; } if (!pastes){ return 'Your previous pastes will be saved in your browser localStorage.';