var LC = function(){
var store = null, engine = null;
var searchOrder = ['localStorage', 'userData', 'globalStorage'];
var engines = {
localStorage:{
test:function(){
return window.localStorage ? true : false;
},
init:function(){
store = localStorage;
},
get:function(key){
return store.getItem(key);
},
set:function(key,value){
return store.setItem(key,value);
},
del:function(key){
return store.removeItem(key);
}
},
globalStorage: {
test: function(){
return window.globalStorage ? true : false;
},
init: function(){
store = globalStorage[document.domain];
},
get: function(key){
return store.getItem(key).value;
},
set: function(key, value){
return store.setItem(key, value);
},
del: function(key){
return store.removeItem(key);
}
},
userData:{
test:function(){
return window.ActiveXObject ? true : false;
},
init:function(){
store = document.documentElement;
store.addBehavior('#default#userdata');
},
get:function(key) {
store.load(key);
return store.getAttribute(key);
},
set:function(key, value) {
store.load(key);
store.setAttribute(key, value);
return store.save(key);
},
del:function(key) {
store.load(key);
store.expires = new Date(315532799000).toUTCString();
return store.save(key);
}
}
};
for(var i = 0,l = searchOrder.length, engine; i < l; i ++){
engine = engines[searchOrder[i]];
if(engine.test()){
try{
engine.init();
break;
}catch(ex){
engine = null;
}
}
}
if(engine){
delete engine.test;
delete engine.init;
}
return engine;
}();
posted on 2010-04-25 22:28
汪杰 阅读(216)
评论(0) 编辑 收藏 引用 所属分类:
javascript