diff options
author | Michael Hamann <michael@content-space.de> | 2011-05-29 22:57:55 +0200 |
---|---|---|
committer | Michael Hamann <michael@content-space.de> | 2011-05-29 23:08:38 +0200 |
commit | 79344f5bffd7dfe74cbfe5e4362425dda4f5b7af (patch) | |
tree | 178492676b091c03ec52f3a99ad0d089447df823 /lib/scripts/cookie.js | |
parent | 5ff127375bd2292958b989dcec18dbca5a8a751f (diff) | |
parent | 61a2640a5e066cac3e06f2673c63622d59da2e8d (diff) | |
download | rpg-79344f5bffd7dfe74cbfe5e4362425dda4f5b7af.tar.gz rpg-79344f5bffd7dfe74cbfe5e4362425dda4f5b7af.tar.bz2 |
Merge branch 'jquery'
Conflicts:
lib/scripts/edit.js
lib/scripts/locktimer.js
Some whitespace (at end of line) cleanup
Diffstat (limited to 'lib/scripts/cookie.js')
-rw-r--r-- | lib/scripts/cookie.js | 74 |
1 files changed, 32 insertions, 42 deletions
diff --git a/lib/scripts/cookie.js b/lib/scripts/cookie.js index d7e6b3550..f7d9b5ffb 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)); }, /** |