From 1c5f7481f4e685ad3ffe9ba48ed47ed75196e64a Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Mon, 22 Aug 2011 16:10:05 +0200 Subject: Update jquery-cookie, cleanup dw_cookie Pulled the current jquery-cookie version from https://github.com/carhartl/jquery-cookie. --- lib/scripts/cookie.js | 73 ++++++++++++--------------------------------------- 1 file changed, 17 insertions(+), 56 deletions(-) (limited to 'lib/scripts/cookie.js') diff --git a/lib/scripts/cookie.js b/lib/scripts/cookie.js index f7d9b5ffb..f97882855 100644 --- a/lib/scripts/cookie.js +++ b/lib/scripts/cookie.js @@ -2,7 +2,7 @@ * 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! +* simple name-value pairs - no complex types! * * You should only use the getValue and setValue methods * @@ -10,7 +10,7 @@ * @author Michal Rezler */ DokuCookie = { - data: Array(), + data: {}, name: 'DOKU_PREFS', /** @@ -19,21 +19,17 @@ DokuCookie = { * @author Andreas Gohr */ setValue: function(key,val){ + var text = ''; this.init(); this.data[key] = val; - // prepare expire date - var now = new Date(); - 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 this.data){ - if (!this.data.hasOwnProperty(key)) continue; - text += '#'+escape(key)+'#'+this.data[key]; - } - this.setCookie(this.name,text.substr(1),now,DOKU_BASE); + jQuery.each(this.data, function (val, key) { + if (this.data.hasOwnProperty(key)) { + text += '#'+encodeURIComponent(key)+'#'+encodeURIComponent(val); + } + }); + jQuery.cookie(this.name,text.substr(1), {expires: 365, path: DOKU_BASE}); }, /** @@ -52,51 +48,16 @@ DokuCookie = { * @author Andreas Gohr */ init: function(){ - if(this.data.length) return; - var text = this.getCookie(this.name); + var text, parts, i; + if(!jQuery.isEmptyObject(this.data)) { + return; + } + text = jQuery.cookie(this.name); if(text){ - var parts = text.split('#'); - for(var i=0; i 0){ - date.setTime(date.getTime() - skew); - } } }; -- cgit v1.2.3