summaryrefslogtreecommitdiff
path: root/lib/scripts/cookie.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/scripts/cookie.js')
-rw-r--r--lib/scripts/cookie.js71
1 files changed, 16 insertions, 55 deletions
diff --git a/lib/scripts/cookie.js b/lib/scripts/cookie.js
index e7ba620c7..3f3375fa7 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 <m.rezler@centrum.cz>
*/
DokuCookie = {
- data: Array(),
+ data: {},
name: 'DOKU_PREFS',
/**
@@ -19,21 +19,17 @@ DokuCookie = {
* @author Andreas Gohr <andi@splitbrain.org>
*/
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];
+ jQuery.each(this.data, function (val, key) {
+ if (this.data.hasOwnProperty(key)) {
+ text += '#'+encodeURIComponent(key)+'#'+encodeURIComponent(val);
}
- this.setCookie(this.name,text.substr(1),now,DOKU_BASE);
+ });
+ jQuery.cookie(this.name,text.substr(1), {expires: 365, path: DOKU_BASE});
},
/**
@@ -52,51 +48,16 @@ DokuCookie = {
* @author Andreas Gohr <andi@splitbrain.org>
*/
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<parts.length; i+=2){
- this.data[unescape(parts[i])] = unescape(parts[i+1]);
+ parts = text.split('#');
+ for(i = 0; i < parts.length; i += 2){
+ this.data[decodeURIComponent(parts[i])] = decodeURIComponent(parts[i+1]);
}
}
- },
-
- /**
- * This sets a cookie by JavaScript
- *
- * @link http://www.webreference.com/js/column8/functions.html
- */
- setCookie: function(name, value, expires_, path_, domain_, secure_) {
- var params = {
- expires: expires_,
- path: path_,
- domain: domain_,
- secure: secure_
- };
-
- jQuery.cookie(name, value, params);
- },
-
- /**
- * This reads a cookie by JavaScript
- *
- * @link http://www.webreference.com/js/column8/functions.html
- */
- getCookie: function(name) {
- return unescape(jQuery.cookie(name));
- },
-
- /**
- * This is needed for the cookie functions
- *
- * @link http://www.webreference.com/js/column8/functions.html
- */
- fixDate: function(date) {
- var base = new Date(0);
- var skew = base.getTime();
- if (skew > 0){
- date.setTime(date.getTime() - skew);
}
- }
};