fix some localStorage bugs
This commit is contained in:
parent
c9d2ac5fcd
commit
64592e7278
4 changed files with 17 additions and 9 deletions
|
@ -119,7 +119,7 @@ Ox.Theme = (function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
localStorage['Ox.theme'] = theme;
|
Ox.localStorage('Ox')('theme', theme);
|
||||||
return that;
|
return that;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -127,31 +127,39 @@ Ox.load = function() {
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
Ox.localStorage <o> localStorage wrapper
|
Ox.localStorage <o> localStorage wrapper
|
||||||
|
() -> <o> key:value pairs
|
||||||
|
(key) -> <*> value
|
||||||
|
(key, val) -> <f> localStorage object
|
||||||
|
({key, val}) -> <f> localStorage object
|
||||||
@*/
|
@*/
|
||||||
Ox.localStorage = function(namespace) {
|
Ox.localStorage = function(namespace) {
|
||||||
if (Ox.isUndefined(localStorage)) {
|
// Ox.Log calls this before Ox.isUndefined is defined
|
||||||
|
if (localStorage === void 0) {
|
||||||
localStorage = {};
|
localStorage = {};
|
||||||
}
|
}
|
||||||
function storage(key, val) {
|
function storage(key, val) {
|
||||||
var ret, value;
|
var ret, value;
|
||||||
if (Ox.isUndefined(key)) {
|
if (arguments.length == 0) {
|
||||||
ret = {};
|
ret = {};
|
||||||
Ox.forEach(localStorage, function(val, key) {
|
Ox.forEach(localStorage, function(val, key) {
|
||||||
if (Ox.startsWith(key, namespace + '.')) {
|
if (Ox.startsWith(key, namespace + '.')) {
|
||||||
ret[key.substr(namespace.length + 1)] = JSON.parse(val);
|
ret[key.substr(namespace.length + 1)] = JSON.parse(val);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (Ox.isUndefined(val)) {
|
} else if (arguments.length == 1 && !Ox.isObject(key)) {
|
||||||
value = localStorage[namespace + '.' + key];
|
value = localStorage[namespace + '.' + key];
|
||||||
ret = Ox.isUndefined(value) ? void 0 : JSON.parse(value);
|
ret = Ox.isUndefined(value) ? void 0 : JSON.parse(value);
|
||||||
} else {
|
} else {
|
||||||
|
args = Ox.makeObject(arguments);
|
||||||
|
Ox.forEach(args, function(val, key) {
|
||||||
localStorage[namespace + '.' + key] = JSON.stringify(val);
|
localStorage[namespace + '.' + key] = JSON.stringify(val);
|
||||||
|
});
|
||||||
ret = this;
|
ret = this;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
storage.delete = function(key) {
|
storage.delete = function(key) {
|
||||||
var keys = Ox.isUndefined(key)
|
var keys = arguments.length == 0
|
||||||
? Object.keys(storage())
|
? Object.keys(storage())
|
||||||
: [key];
|
: [key];
|
||||||
keys.forEach(function(key) {
|
keys.forEach(function(key) {
|
||||||
|
@ -166,7 +174,7 @@ Ox.Log <f> Logging module
|
||||||
@*/
|
@*/
|
||||||
Ox.Log = (function() {
|
Ox.Log = (function() {
|
||||||
var storage = Ox.localStorage('Ox'),
|
var storage = Ox.localStorage('Ox'),
|
||||||
log = storage('Log') || {filter: [], filterEnabled: true};
|
log = storage('Log') || {filter: [], filterEnabled: true},
|
||||||
that = function() {
|
that = function() {
|
||||||
var ret;
|
var ret;
|
||||||
if (arguments.length == 0) {
|
if (arguments.length == 0) {
|
||||||
|
|
|
@ -291,8 +291,7 @@ Ox.isUndefined <f> Tests if a value is undefined
|
||||||
@*/
|
@*/
|
||||||
|
|
||||||
Ox.isUndefined = function(val) {
|
Ox.isUndefined = function(val) {
|
||||||
// fixme: val === void 0 is also nice
|
return val === void 0;
|
||||||
return typeof val == 'undefined';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
|
|
|
@ -78,6 +78,7 @@ def build_oxjs(geo):
|
||||||
write_link(link_source, link_target)
|
write_link(link_source, link_target)
|
||||||
|
|
||||||
# Ox.js
|
# Ox.js
|
||||||
|
# FIXME: Document what exactly the following dependecies are!
|
||||||
filenames = [
|
filenames = [
|
||||||
['Fallback.js', 'Core.js'],
|
['Fallback.js', 'Core.js'],
|
||||||
['Collection.js', 'Math.js']
|
['Collection.js', 'Math.js']
|
||||||
|
|
Loading…
Add table
Reference in a new issue