diff options
author | ahriman <ahriman@falte.red> | 2018-12-03 19:22:25 -0500 |
---|---|---|
committer | ahriman <ahriman@falte.red> | 2018-12-03 19:22:25 -0500 |
commit | 0ae8cbf5c0b1a198b963490985b7738392ebcb97 (patch) | |
tree | b2c77ae72c6b717e2b97492065196ac5ffb2d9e2 /wiki/lib/scripts/cookie.js | |
parent | f57f6cc5a2d159f90168d292437dc4bd8cd7f934 (diff) | |
download | site-0ae8cbf5c0b1a198b963490985b7738392ebcb97.tar.gz |
installed dokuwiki, added to navbar, updated news
Diffstat (limited to 'wiki/lib/scripts/cookie.js')
-rw-r--r-- | wiki/lib/scripts/cookie.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/wiki/lib/scripts/cookie.js b/wiki/lib/scripts/cookie.js new file mode 100644 index 0000000..8417d20 --- /dev/null +++ b/wiki/lib/scripts/cookie.js @@ -0,0 +1,64 @@ +/** +* Handles the cookie used by several JavaScript functions +* +* Only a single cookie is written and read. You may only save +* simple 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> +*/ +var DokuCookie = { + data: {}, + name: 'DOKU_PREFS', + + /** + * Save a value to the cookie + * + * @author Andreas Gohr <andi@splitbrain.org> + */ + setValue: function(key,val){ + var text = [], + _this = this; + this.init(); + this.data[key] = val; + + //save the whole data array + jQuery.each(_this.data, function (key, val) { + if (_this.data.hasOwnProperty(key)) { + text.push(encodeURIComponent(key)+'#'+encodeURIComponent(val)); + } + }); + jQuery.cookie(this.name, text.join('#'), {expires: 365, path: DOKU_COOKIE_PARAM.path, secure: DOKU_COOKIE_PARAM.secure}); + }, + + /** + * Get a Value from the Cookie + * + * @author Andreas Gohr <andi@splitbrain.org> + */ + getValue: function(key){ + this.init(); + return this.data[key]; + }, + + /** + * Loads the current set cookie + * + * @author Andreas Gohr <andi@splitbrain.org> + */ + init: function(){ + var text, parts, i; + if(!jQuery.isEmptyObject(this.data)) { + return; + } + text = jQuery.cookie(this.name); + if(text){ + parts = text.split('#'); + for(i = 0; i < parts.length; i += 2){ + this.data[decodeURIComponent(parts[i])] = decodeURIComponent(parts[i+1]); + } + } + } +}; |