-
Notifications
You must be signed in to change notification settings - Fork 70
/
persist-min.js
1 lines (1 loc) · 7.2 KB
/
persist-min.js
1
(function(){if(!window.google||!google.gears){var d=null;if("undefined"!=typeof GearsFactory)d=new GearsFactory;else try{d=new ActiveXObject("Gears.Factory"),-1!=d.getBuildInfo().indexOf("ie_mobile")&&d.privateSetGlobalObject(this)}catch(e){"undefined"!=typeof navigator.mimeTypes&&navigator.mimeTypes["application/x-googlegears"]&&(d=document.createElement("object"),d.style.display="none",d.width=0,d.height=0,d.type="application/x-googlegears",document.documentElement.appendChild(d))}d&&(window.google|| (google={}),google.gears||(google.gears={factory:d}))}})(); Persist=function(){var d,e,c,l,q,n;n=function(){var a=["expires","path","domain"],b=escape,f=unescape,d=document,c,e=function(s,f){var d,p,c=[],e=2<arguments.length?arguments[2]:{};c.push(b(s)+"="+b(f));for(var g=0;g<a.length;g++)d=a[g],(p=e[d])&&c.push(d+"="+p);e.secure&&c.push("secure");return c.join("; ")};c={set:function(a,b){var f=2<arguments.length?arguments[2]:{},c=new Date;c.setTime(c.getTime());var k={};if(f.expires)if(-1==f.expires)k.expires=-1;else{var m=864E5*f.expires;k.expires=new Date(c.getTime()+ m);k.expires=k.expires.toGMTString()}c=["path","domain","secure"];for(m=0;m<c.length;m++)f[c[m]]&&(k[c[m]]=f[c[m]]);f=e(a,b,k);d.cookie=f;return b},has:function(a){a=b(a);var f=d.cookie,c=f.indexOf(a+"="),f=f.substring(0,a.length);return!c&&a!=f||0>c?!1:!0},get:function(a){a=b(a);var c=d.cookie,e=c.indexOf(a+"="),p=e+a.length+1,k=c.substring(0,a.length);if(!e&&a!=k||0>e)return null;a=c.indexOf(";",p);0>a&&(a=c.length);return f(c.substring(p,a))},remove:function(a){var b=c.get(a);d.cookie=e(a,"",{expires:"Thu, 01-Jan-1970 00:00:01 GMT"}); return b},keys:function(){for(var a=d.cookie.split("; "),b,c=[],e=0;e<a.length;e++)b=a[e].split("="),c.push(f(b[0]));return c},all:function(){for(var a=d.cookie.split("; "),b,c=[],e=0;e<a.length;e++)b=a[e].split("="),c.push([f(b[0]),f(b[1])]);return c},version:"0.2.1",enabled:!1};c.enabled=function(){var a=new Date,a=a.toGMTString();this.set("__EC_TEST__",a);return this.enabled=this.remove("__EC_TEST__")==a}.call(c);return c}();var t=function(){return Array.prototype.indexOf?function(a,b){return Array.prototype.indexOf.call(a, b)}:function(a,b){for(var c=0,d=a.length;c<d;c++)if(a[c]==b)return c;return-1}}();q=function(){};c=function(a){return"PS"+a.replace(/_/g,"__").replace(/ /g,"_s")};var h="localstorage globalstorage gears cookie ie flash".split(" "),u=/^[a-z][a-z0-9_ \-]+$/i,r="init get set remove load save iterate".split(" "),v={autostart:!0};e={gears:{size:-1,test:function(){return window.google&&window.google.gears?!0:!1},methods:{init:function(){var a;a=this.db=google.gears.factory.create("beta.database");a.open(c(this.name)); a.execute("CREATE TABLE IF NOT EXISTS persist_data (k TEXT UNIQUE NOT NULL PRIMARY KEY, v TEXT NOT NULL)").close()},get:function(a){var b=this.db,c;b.execute("BEGIN").close();a=b.execute("SELECT v FROM persist_data WHERE k = ?",[a]);c=a.isValidRow()?a.field(0):null;a.close();b.execute("COMMIT").close();return c},set:function(a,b){var c=this.db;c.execute("BEGIN").close();c.execute("DELETE FROM persist_data WHERE k = ?",[a]).close();c.execute("INSERT INTO persist_data(k, v) VALUES (?, ?)",[a,b]).close(); c.execute("COMMIT").close();return b},remove:function(a){var b=this.db;b.execute("BEGIN").close();b.execute("DELETE FROM persist_data WHERE k = ?",[a]).close();b.execute("COMMIT").close();return!0},iterate:function(a,b){var c;for(c=this.db.execute("SELECT * FROM persist_data");c.isValidRow();)a.call(b||this,c.field(0),c.field(1)),c.next();c.close()}}},globalstorage:{size:5242880,test:function(){return window.globalStorage?!0:!1},methods:{key:function(a){return c(this.name)+c(a)},init:function(){this.store= globalStorage[this.o.domain]},get:function(a){a=this.key(a);return this.store.getItem(a)},set:function(a,b){a=this.key(a);this.store.setItem(a,b);return b},remove:function(a){var b;a=this.key(a);b=this.store.getItem[a];this.store.removeItem(a);return b}}},localstorage:{size:-1,test:function(){try{if(window.localStorage&&void 0==window.localStorage.setItem("persistjs_test_local_storage",null))if(window.localStorage.removeItem("persistjs_test_local_storage"),/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){if(9<= RegExp.$1)return!0;if("file:"==window.location.protocol)return!1}else return!0;else return!1;return window.localStorage?!0:!1}catch(a){return!1}},methods:{key:function(a){return this.name+">"+a},init:function(){this.store=localStorage},get:function(a){a=this.key(a);return this.store.getItem(a)},set:function(a,b){a=this.key(a);this.store.setItem(a,b);return b},remove:function(a){var b;a=this.key(a);b=this.store.getItem(a);this.store.removeItem(a);return b},iterate:function(a,b){for(var c=this.store, d,e,h=0;h<c.length;h++)d=c.key(h),e=d.split(">"),2==e.length&&e[0]==this.name&&a.call(b||this,e[1],c.getItem(d))}}},ie:{prefix:"_persist_data-",size:65536,test:function(){return window.ActiveXObject?!0:!1},make_userdata:function(a){var b=document.createElement("div");b.id=a;b.style.display="none";b.addBehavior("#default#userdata");document.body.appendChild(b);return b},methods:{init:function(){var a=e.ie.prefix+c(this.name);this.el=e.ie.make_userdata(a);this.o.defer&&this.load()},get:function(a){a= c(a);this.o.defer||this.load();return this.el.getAttribute(a)},set:function(a,b){a=c(a);this.el.setAttribute(a,b);this.o.defer||this.save();return b},remove:function(a){var b;a=c(a);this.o.defer||this.load();b=this.el.getAttribute(a);this.el.removeAttribute(a);this.o.defer||this.save();return b},load:function(){this.el.load(c(this.name))},save:function(){this.el.save(c(this.name))}}},cookie:{delim:":",size:4E3,test:function(){return d.Cookie.enabled?!0:!1},methods:{key:function(a){return this.name+ e.cookie.delim+a},get:function(a,b){a=this.key(a);return n.get(a)},set:function(a,b,c){a=this.key(a);n.set(a,b,this.o);return b},remove:function(a,b){a=this.key(a);return b=n.remove(a)}}},flash:{test:function(){return swfobject?8<=swfobject.getFlashPlayerVersion().major?!0:!1:!1},methods:{init:function(){if(!e.flash.el){var a,b;a=document.createElement("div");a.id="_persist_flash_wrap";b=document.createElement("div");b.id="_persist_flash";a.appendChild(b);document.body.appendChild(a);e.flash.el=swfobject.createSWF({id:"_persist_flash", data:this.o.swf_path||"persist.swf",width:1,height:1},v,"_persist_flash")}this.el=e.flash.el},get:function(a){a=c(a);return this.el.get(this.name,a)},set:function(a,b){a=c(a);return this.el.set(this.name,a,b)},remove:function(a){a=c(a);return this.el.remove(this.name,a)}}}};l=function(){var a,b,c=h;a=0;for(var g=r.length;a<g;a++)d.Store.prototype[r[a]]=q;d.type=null;d.size=-1;for(var g=0,l=c.length;!d.type&&g<l;g++)if(a=e[c[g]],a.test())for(b in d.type=c[g],d.size=a.size,a.methods)d.Store.prototype[b]= a.methods[b];d._init=!0};d={VERSION:"0.3.1",type:null,size:0,add:function(a){e[a.id]=a;h=[a.id].concat(h);l()},remove:function(a){var b=t(h,a);0>b||(h.splice(b,1),delete e[a],l())},Cookie:n,Store:function(a,b){if(!u.exec(a))throw Error("Invalid name");if(!d.type)throw Error("No suitable storage found");b=b||{};this.name=a;b.domain=b.domain||location.hostname||"localhost";b.domain=b.domain.replace(/:\d+$/,"");b.domain="localhost"==b.domain?"":b.domain;this.o=b;b.expires=b.expires||730;b.path=b.path|| "/";this.o.search_order&&(h=this.o.search_order,l());this.init()}};l();return d}();