update Ox.Log

This commit is contained in:
rlx 2011-11-04 16:04:46 +00:00
parent dce2843303
commit 8ef45bb1cb
2 changed files with 21 additions and 20 deletions

View file

@ -117,6 +117,7 @@ Ox.Theme = (function() {
}); });
}); });
} }
localStorage && localStorage.OxTheme = theme;
return that; return that;
} }

View file

@ -122,48 +122,48 @@ Ox.load = function() {
}; };
Ox.Log = (function() { Ox.Log = (function() {
var filter = localStorage && localStorage.filter var log = localStorage && localStorage.OxLog
? JSON.parse(localStorage.filter) ? JSON.parse(localStorage.OxLog)
: {enabled: true, matches: []}, : {enabled: false, filter: []},
that = function() { that = function() {
return that.log.apply(null, arguments); return that.log.apply(null, arguments);
}; };
function saveFilter() { function save() {
if (localStorage) { if (localStorage) {
localStorage.filter = JSON.stringify(filter); localStorage.OxLog = JSON.stringify(log);
} }
} }
that.disable = function() {
log.enabled = false;
save();
};
that.enable = function() {
log.enabled = true;
save();
};
that.filter = function(val) { that.filter = function(val) {
var ret; var ret;
if (Ox.isUndefined(val)) { if (Ox.isUndefined(val)) {
ret = filter.matches; ret = log.filter;
} else { } else {
filter.matches = Ox.toArray(val); log.filter = Ox.toArray(val);
saveFilter(); save();
ret = that; ret = that;
} }
return ret; return ret;
}; };
that.filter.add = function(val) { that.filter.add = function(val) {
return that.filter(Ox.unique(Ox.merge(filter, Ox.toArray(val)))); return that.filter(Ox.unique(Ox.merge(log.filter, Ox.toArray(val))));
};
that.filter.disable = function() {
filter.enabled = false;
saveFilter();
};
that.filter.enable = function() {
filter.enabled = true;
saveFilter();
}; };
that.filter.remove = function(val) { that.filter.remove = function(val) {
val = Ox.toArray(val); val = Ox.toArray(val);
return that.filter(filter.matches.filter(function(v) { return that.filter(log.filter.filter(function(v) {
return val.indexOf(v) == -1; return val.indexOf(v) == -1;
})); }));
}; };
that.log = function log() { that.log = function log() {
var args = Ox.makeArray(arguments), date, ret; var args = Ox.makeArray(arguments), date, ret;
if (!filter.enabled || filter.matches.indexOf(args[0]) > -1) { if (log.enabled && log.filter.indexOf(args[0]) > -1) {
date = new Date(); date = new Date();
args.unshift( args.unshift(
Ox.formatDate(date, '%H:%M:%S.') + (+date).toString().substr(-3), Ox.formatDate(date, '%H:%M:%S.') + (+date).toString().substr(-3),