aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib/scripts/cookie.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/scripts/cookie.js')
-rw-r--r--lib/scripts/cookie.js97
1 files changed, 51 insertions, 46 deletions
diff --git a/lib/scripts/cookie.js b/lib/scripts/cookie.js
index 1fccf85ba..4904117ee 100644
--- a/lib/scripts/cookie.js
+++ b/lib/scripts/cookie.js
@@ -1,97 +1,102 @@
/**
- * 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!
- *
- *
- * @author Andreas Gohr <andi@splitbrain.org>
- * @author Michal Rezler <m.rezler@centrum.cz>
- */
-
-var setDokuCookie, getDokuCookie;
-
-(function ($) {
- var init, setCookie, fixDate;
-
- var data = Array();
- var name = 'DOKU_PREFS';
+* 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',
/**
* Save a value to the cookie
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
- setDokuCookie = function(key,val){
- init();
- data[key] = val;
+ setValue: function(key,val){
+ this.init();
+ this.data[key] = val;
// prepare expire date
var now = new Date();
- 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 data){
- if (!data.hasOwnProperty(key)) continue;
- text += '#'+escape(key)+'#'+data[key];
+ for(var key in this.data){
+ if (!this.data.hasOwnProperty(key)) continue;
+ text += '#'+escape(key)+'#'+this.data[key];
}
- setCookie(name,text.substr(1),now,DOKU_BASE);
- };
+ this.setCookie(this.name,text.substr(1),now,DOKU_BASE);
+ },
/**
* Get a Value from the Cookie
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
- getDokuCookie = function(key){
- init();
- return data[key];
- };
+ getValue: function(key){
+ this.init();
+ return this.data[key];
+ },
/**
* Loads the current set cookie
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
- init = function(){
- if(data.length) return;
- var text = $.cookie(name);
-
+ init: function(){
+ 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){
- data[unescape(parts[i])] = unescape(parts[i+1]);
+ this.data[unescape(parts[i])] = unescape(parts[i+1]);
}
}
- };
+ },
/**
- * This sets a cookie
+ * 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 = {
+ setCookie: function(name, value, expires_, path_, domain_, secure_) {
+ var params = {
expires: expires_,
path: path_,
domain: domain_,
secure: secure_,
- };
- $.cookie(name, value, params);
- };
+ };
+
+ 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) {
+ fixDate: function(date) {
var base = new Date(0);
var skew = base.getTime();
if (skew > 0){
date.setTime(date.getTime() - skew);
}
- };
-
-}(jQuery));
+ }
+}; \ No newline at end of file