fallback on cookies if localStorage is null or undefined

This commit is contained in:
Calvin Montgomery 2013-07-02 22:40:40 -04:00
parent 91a2fcb61d
commit 6a6dd7bc21
2 changed files with 11 additions and 2 deletions

View File

@ -68,9 +68,18 @@ var PL_FROM = 0;
var PL_TO = 0;
var FILTER_FROM = 0;
var FILTER_TO = 0;
var NO_STORAGE = typeof localStorage == "undefined" || localStorage === null;
function getOpt(k) {
return NO_STORAGE ? readCookie(k) : localStorage.getItem(k);
}
function setOpt(k, v) {
NO_STORAGE ? createCookie(k, v, 1000) : localStorage.setItem(k, v);
}
function getOrDefault(k, def) {
var v = localStorage.getItem(k);
var v = getOpt(k);
if(v === null)
return def;
if(v === "true")

View File

@ -507,7 +507,7 @@ function showOptionsMenu() {
function saveOpts() {
for(var key in USEROPTS) {
localStorage.setItem(key, USEROPTS[key]);
setOpt(key, USEROPTS[key]);
}
}