From fdfb9c6a2877dcbadeab697aad779bea76780965 Mon Sep 17 00:00:00 2001 From: Michal Rezler Date: Sat, 26 Mar 2011 15:42:22 +0100 Subject: cookie.js is jQueryfied, added jQuery-cookie-plugin --- lib/scripts/cookie.js | 99 ++++++++++++++++++++++----------------------------- 1 file changed, 42 insertions(+), 57 deletions(-) (limited to 'lib/scripts/cookie.js') diff --git a/lib/scripts/cookie.js b/lib/scripts/cookie.js index d7e6b3550..1fccf85ba 100644 --- a/lib/scripts/cookie.js +++ b/lib/scripts/cookie.js @@ -4,109 +4,94 @@ * Only a single cookie is written and read. You may only save * sime name-value pairs - no complex types! * - * You should only use the getValue and setValue methods * * @author Andreas Gohr + * @author Michal Rezler */ -DokuCookie = { - data: Array(), - name: 'DOKU_PREFS', + +var setDokuCookie, getDokuCookie; + +(function ($) { + var init, setCookie, fixDate; + + var data = Array(); + var name = 'DOKU_PREFS'; /** * Save a value to the cookie * * @author Andreas Gohr */ - setValue: function(key,val){ - DokuCookie.init(); - DokuCookie.data[key] = val; + setDokuCookie = function(key,val){ + init(); + data[key] = val; // prepare expire date var now = new Date(); - DokuCookie.fixDate(now); + fixDate(now); now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000); //expire in a year //save the whole data array var text = ''; - for(var key in DokuCookie.data){ - if (!DokuCookie.data.hasOwnProperty(key)) continue; - text += '#'+escape(key)+'#'+DokuCookie.data[key]; + for(var key in data){ + if (!data.hasOwnProperty(key)) continue; + text += '#'+escape(key)+'#'+data[key]; } - DokuCookie.setCookie(DokuCookie.name,text.substr(1),now,DOKU_BASE); - }, + setCookie(name,text.substr(1),now,DOKU_BASE); + }; /** * Get a Value from the Cookie * * @author Andreas Gohr */ - getValue: function(key){ - DokuCookie.init(); - return DokuCookie.data[key]; - }, + getDokuCookie = function(key){ + init(); + return data[key]; + }; /** * Loads the current set cookie * * @author Andreas Gohr */ - init: function(){ - if(DokuCookie.data.length) return; - var text = DokuCookie.getCookie(DokuCookie.name); + init = function(){ + if(data.length) return; + var text = $.cookie(name); + if(text){ var parts = text.split('#'); for(var i=0; i 0){ date.setTime(date.getTime() - skew); } - } -}; + }; + +}(jQuery)); -- cgit v1.2.3 From 2ed49e2ac1bc9ed8a9d514d3ea9515e455768152 Mon Sep 17 00:00:00 2001 From: Michal Rezler Date: Mon, 28 Mar 2011 23:09:13 +0200 Subject: JS API is corrected to the original state --- lib/scripts/cookie.js | 97 +++++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 46 deletions(-) (limited to 'lib/scripts/cookie.js') diff --git a/lib/scripts/cookie.js b/lib/scripts/cookie.js index 1fccf85ba..4904117ee 100644 --- a/lib/scripts/cookie.js +++ b/lib/scripts/cookie.js @@ -1,97 +1,102 @@ /** - * Handles the cookie used by several JavaScript functions - * - * Only a single cookie is written and read. You may only save - * sime name-value pairs - no complex types! - * - * - * @author Andreas Gohr - * @author Michal Rezler - */ - -var setDokuCookie, getDokuCookie; - -(function ($) { - var init, setCookie, fixDate; - - var data = Array(); - var name = 'DOKU_PREFS'; +* Handles the cookie used by several JavaScript functions +* +* Only a single cookie is written and read. You may only save +* sime name-value pairs - no complex types! +* +* You should only use the getValue and setValue methods +* +* @author Andreas Gohr +* @author Michal Rezler +*/ +DokuCookie = { + data: Array(), + name: 'DOKU_PREFS', /** * Save a value to the cookie * * @author Andreas Gohr */ - setDokuCookie = function(key,val){ - init(); - data[key] = val; + setValue: function(key,val){ + this.init(); + this.data[key] = val; // prepare expire date var now = new Date(); - fixDate(now); + this.fixDate(now); now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000); //expire in a year //save the whole data array var text = ''; - for(var key in data){ - if (!data.hasOwnProperty(key)) continue; - text += '#'+escape(key)+'#'+data[key]; + for(var key in this.data){ + if (!this.data.hasOwnProperty(key)) continue; + text += '#'+escape(key)+'#'+this.data[key]; } - setCookie(name,text.substr(1),now,DOKU_BASE); - }; + this.setCookie(this.name,text.substr(1),now,DOKU_BASE); + }, /** * Get a Value from the Cookie * * @author Andreas Gohr */ - getDokuCookie = function(key){ - init(); - return data[key]; - }; + getValue: function(key){ + this.init(); + return this.data[key]; + }, /** * Loads the current set cookie * * @author Andreas Gohr */ - init = function(){ - if(data.length) return; - var text = $.cookie(name); - + init: function(){ + if(this.data.length) return; + var text = this.getCookie(this.name); if(text){ var parts = text.split('#'); for(var i=0; i 0){ date.setTime(date.getTime() - skew); } - }; - -}(jQuery)); + } +}; \ No newline at end of file -- cgit v1.2.3