2 * Copyright 2005 - 2009 The Citadel Team
3 * Licensed under the GPL V3
4 * Webcit preference code
6 var persistentStorage = false;
7 /* DOM5 storage disabled for now.. we want localStorage which isn't as widely available yet */
8 //if (window.sessionStorage) {
9 // persistentStorage = true;
12 this.cookieValCache = new Object();
13 this.noExpire = "Mon, 18 Jan 2038 5:14:07 AM";
16 function readPref(name) {
17 if (persistentStorage) {
18 return sessionStorage.getItem(name);
20 return this.cookieValCache[name];
24 function setPref(name, value) {
25 if (persistentStorage) {
26 sessionStorage.setItem(name, value);
28 document.cookie = "WC_" + name + "="+value+";expires="+this.noExpire;
29 // this.cookieValCache[name] = value;
34 function loadLocal() {
35 if (!persistentStorage) {
36 var cookies = document.cookie.split(";");
37 for(var i=0; i<cookies.length; i++) {
38 var cookie = cookies[i].split("=");
40 if (name.charAt(0) == " ") {
41 name = name.substr(1);
43 if (name.substr(0, 3) == "WC_") {
44 name = name.substr(3);
45 this.cookieValCache[name] = cookie[1];
46 if (!!window.console) {
47 console.log(name+"="+cookie[1]);
54 function saveLocal() {
55 if (!persistentStorage) {
56 // First we purge cookies with WC_ infront
57 var cookies = document.cookie.split(";");
58 var numOfCookies = cookies.length;
59 var finalCookieString = "";
60 for(var i=0; i<numOfCookies; i++)
61 var cookie = cookies[i].split("=");
63 if (name.substr(0, 3) != "WC_") {
64 finalCookieString += cookies[i] + ";";
67 for(key in this.cookieValCache) {
68 var val = this.cookieValCache[key];
69 finalCookieString += "WC_" + key+"="+val+";";
71 document.cookie = finalCookieString;
74 WCPrefs.prototype.saveLocal = saveLocal;
75 WCPrefs.prototype.loadLocal = loadLocal;
76 WCPrefs.prototype.setPref = setPref;
77 WCPrefs.prototype.readPref = readPref;
78 var ctdlLocalPrefs = null;
80 function setupPrefEngine() {
81 ctdlLocalPrefs = new WCPrefs();
82 ctdlLocalPrefs.loadLocal();