diff options
Diffstat (limited to 'lib/scripts/cookie.js')
-rw-r--r-- | lib/scripts/cookie.js | 76 |
1 files changed, 33 insertions, 43 deletions
diff --git a/lib/scripts/cookie.js b/lib/scripts/cookie.js index d7e6b3550..4904117ee 100644 --- a/lib/scripts/cookie.js +++ b/lib/scripts/cookie.js @@ -1,13 +1,14 @@ /** - * 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 <andi@splitbrain.org> - */ +* 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 <andi@splitbrain.org> +* @author Michal Rezler <m.rezler@centrum.cz> +*/ DokuCookie = { data: Array(), name: 'DOKU_PREFS', @@ -18,21 +19,21 @@ DokuCookie = { * @author Andreas Gohr <andi@splitbrain.org> */ setValue: function(key,val){ - DokuCookie.init(); - DokuCookie.data[key] = val; + this.init(); + this.data[key] = val; // prepare expire date var now = new Date(); - DokuCookie.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 DokuCookie.data){ - if (!DokuCookie.data.hasOwnProperty(key)) continue; - text += '#'+escape(key)+'#'+DokuCookie.data[key]; + for(var key in this.data){ + if (!this.data.hasOwnProperty(key)) continue; + text += '#'+escape(key)+'#'+this.data[key]; } - DokuCookie.setCookie(DokuCookie.name,text.substr(1),now,DOKU_BASE); + this.setCookie(this.name,text.substr(1),now,DOKU_BASE); }, /** @@ -41,8 +42,8 @@ DokuCookie = { * @author Andreas Gohr <andi@splitbrain.org> */ getValue: function(key){ - DokuCookie.init(); - return DokuCookie.data[key]; + this.init(); + return this.data[key]; }, /** @@ -51,12 +52,12 @@ DokuCookie = { * @author Andreas Gohr <andi@splitbrain.org> */ init: function(){ - if(DokuCookie.data.length) return; - var text = DokuCookie.getCookie(DokuCookie.name); + if(this.data.length) return; + var text = this.getCookie(this.name); if(text){ var parts = text.split('#'); for(var i=0; i<parts.length; i+=2){ - DokuCookie.data[unescape(parts[i])] = unescape(parts[i+1]); + this.data[unescape(parts[i])] = unescape(parts[i+1]); } } }, @@ -66,13 +67,15 @@ DokuCookie = { * * @link http://www.webreference.com/js/column8/functions.html */ - setCookie: function(name, value, expires, path, domain, secure) { - var curCookie = name + "=" + escape(value) + - ((expires) ? "; expires=" + expires.toGMTString() : "") + - ((path) ? "; path=" + path : "") + - ((domain) ? "; domain=" + domain : "") + - ((secure) ? "; secure" : ""); - document.cookie = curCookie; + setCookie: function(name, value, expires_, path_, domain_, secure_) { + var params = { + expires: expires_, + path: path_, + domain: domain_, + secure: secure_, + }; + + jQuery.cookie(name, value, params); }, /** @@ -81,20 +84,7 @@ DokuCookie = { * @link http://www.webreference.com/js/column8/functions.html */ getCookie: function(name) { - var dc = document.cookie; - var prefix = name + "="; - var begin = dc.indexOf("; " + prefix); - if (begin == -1) { - begin = dc.indexOf(prefix); - if (begin !== 0){ return null; } - } else { - begin += 2; - } - var end = document.cookie.indexOf(";", begin); - if (end == -1){ - end = dc.length; - } - return unescape(dc.substring(begin + prefix.length, end)); + return unescape(jQuery.cookie(name)); }, /** @@ -109,4 +99,4 @@ DokuCookie = { date.setTime(date.getTime() - skew); } } -}; +};
\ No newline at end of file |