more font size tweaks.
[citadel.git] / webcit / static / wcpref.js
1 /*
2  * Copyright 2005 - 2009 The Citadel Team
3  * Licensed under the GPL V3
4  * Webcit preference code 
5  */
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;
10 //}
11 function WCPrefs() {
12   this.cookieValCache = new Object();
13   this.noExpire = "Mon, 18 Jan 2038 5:14:07 AM";
14 }
15
16 function readPref(name) {
17   if (persistentStorage) {
18     return sessionStorage.getItem(name);
19   } else {
20     return this.cookieValCache[name];
21   }
22 }
23
24 function setPref(name, value) {
25   if (persistentStorage) {
26     sessionStorage.setItem(name, value);
27   } else {
28     document.cookie = "WC_" + name + "="+value+";expires="+this.noExpire;
29     //    this.cookieValCache[name] = value; 
30     //this.saveLocal();
31   }
32 }
33
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("=");
39       var name = cookie[0];
40       if (name.charAt(0) == " ") {
41         name = name.substr(1);
42       }
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]);
48         }
49       }
50     }
51   }
52 }
53
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("=");
62       var name = cookie[0];
63       if (name.substr(0, 3) != "WC_") {
64         finalCookieString += cookies[i] + ";";
65       }
66     }
67     for(key in this.cookieValCache) {
68       var val = this.cookieValCache[key];
69       finalCookieString += "WC_" + key+"="+val+";";
70     }
71     document.cookie = finalCookieString;
72 }
73
74 WCPrefs.prototype.saveLocal = saveLocal;
75 WCPrefs.prototype.loadLocal = loadLocal;
76 WCPrefs.prototype.setPref = setPref;
77 WCPrefs.prototype.readPref = readPref;
78 var ctdlLocalPrefs = null;
79 setupPrefEngine();
80 function setupPrefEngine() {
81   ctdlLocalPrefs = new WCPrefs();
82   ctdlLocalPrefs.loadLocal();
83 }