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;
}

View file

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