fix some localStorage bugs

This commit is contained in:
rolux 2011-12-30 21:21:33 +05:30
parent 64592e7278
commit 7f249ff12b

View file

@ -133,10 +133,7 @@ Ox.localStorage <o> localStorage wrapper
({key, val}) -> <f> localStorage object ({key, val}) -> <f> localStorage object
@*/ @*/
Ox.localStorage = function(namespace) { Ox.localStorage = function(namespace) {
// Ox.Log calls this before Ox.isUndefined is defined window.localStorage = window.localStorage || {};
if (localStorage === void 0) {
localStorage = {};
}
function storage(key, val) { function storage(key, val) {
var ret, value; var ret, value;
if (arguments.length == 0) { if (arguments.length == 0) {
@ -146,9 +143,10 @@ Ox.localStorage = function(namespace) {
ret[key.substr(namespace.length + 1)] = JSON.parse(val); ret[key.substr(namespace.length + 1)] = JSON.parse(val);
} }
}); });
} else if (arguments.length == 1 && !Ox.isObject(key)) { } else if (arguments.length == 1 && typeof key == 'string') {
// This gets called by Ox.Log before Type.js has loaded
value = localStorage[namespace + '.' + key]; value = localStorage[namespace + '.' + key];
ret = Ox.isUndefined(value) ? void 0 : JSON.parse(value); ret = value === void 0 ? void 0 : JSON.parse(value);
} else { } else {
args = Ox.makeObject(arguments); args = Ox.makeObject(arguments);
Ox.forEach(args, function(val, key) { Ox.forEach(args, function(val, key) {
@ -174,7 +172,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) {
@ -188,7 +186,7 @@ Ox.Log = (function() {
if (!Ox.isUndefined(val)) { if (!Ox.isUndefined(val)) {
that.filter.enable(); that.filter.enable();
log.filter = Ox.toArray(val); log.filter = Ox.toArray(val);
storage('Log', log); storage('log', log);
} }
return log.filter; return log.filter;
}; };
@ -197,11 +195,11 @@ Ox.Log = (function() {
}; };
that.filter.disable = function() { that.filter.disable = function() {
log.filterEnabled = false; log.filterEnabled = false;
storage('Log', log); storage('log', log);
}; };
that.filter.enable = function() { that.filter.enable = function() {
log.filterEnabled = true; log.filterEnabled = true;
storage('Log', log); storage('log', log);
}; };
that.filter.remove = function(val) { that.filter.remove = function(val) {
val = Ox.toArray(val); val = Ox.toArray(val);