/** * 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 */ DokuCookie = { data: Array(), name: 'DOKU_PREFS', /** * Save a value to the cookie * * @author Andreas Gohr */ setValue: function(key,val){ DokuCookie.init(); DokuCookie.data[key] = val; // prepare expire date var now = new Date(); DokuCookie.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]; } DokuCookie.setCookie(DokuCookie.name,text.substr(1),now,DOKU_BASE); }, /** * Get a Value from the Cookie * * @author Andreas Gohr */ getValue: function(key){ DokuCookie.init(); return DokuCookie.data[key]; }, /** * Loads the current set cookie * * @author Andreas Gohr */ init: function(){ if(DokuCookie.data.length) return; var text = DokuCookie.getCookie(DokuCookie.name); if(text){ var parts = text.split('#'); for(var i=0; i 0){ date.setTime(date.getTime() - skew); } } };