Skip to content

Commit

Permalink
More Cookie Removal :- Update Persist.JS cookie enabled test to HTML5
Browse files Browse the repository at this point in the history
  • Loading branch information
GedMarc committed Jul 10, 2020
1 parent fc0c3ea commit a910b97
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 485 deletions.
2 changes: 1 addition & 1 deletion demos/js/jquery.layout.state.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
/**
Persist-JS
*/
(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}();
(function(){if(window.google&&google.gears){return}var a=null;if(typeof GearsFactory!="undefined"){a=new GearsFactory()}else{try{a=new ActiveXObject("Gears.Factory");if(a.getBuildInfo().indexOf("ie_mobile")!=-1){a.privateSetGlobalObject(this)}}catch(b){if((typeof navigator.mimeTypes!="undefined")&&navigator.mimeTypes["application/x-googlegears"]){a=document.createElement("object");a.style.display="none";a.width=0;a.height=0;a.type="application/x-googlegears";document.documentElement.appendChild(a)}}}if(!a){return}if(!window.google){google={}}if(!google.gears){google.gears={factory:a}}})();Persist=(function(){var i="0.3.1",d,b,g,h,e,f;f=(function(){var q="Thu, 01-Jan-1970 00:00:01 GMT",k=1000*60*60*24,r=["expires","path","domain"],m=escape,l=unescape,p=document,n;var s=function(){var t=new Date();t.setTime(t.getTime());return t};var j=function(x,A){var w,v,z,y=[],u=(arguments.length>2)?arguments[2]:{};y.push(m(x)+"="+m(A));for(var t=0;t<r.length;t++){v=r[t];z=u[v];if(z){y.push(v+"="+z)}}if(u.secure){y.push("secure")}return y.join("; ")};var o=function(){return navigator.cookieEnabled};n={set:function(B,x){var u=(arguments.length>2)?arguments[2]:{},v=s(),A,z={};if(u.expires){if(u.expires==-1){z.expires=-1}else{var w=u.expires*k;z.expires=new Date(v.getTime()+w);z.expires=z.expires.toGMTString()}}var C=["path","domain","secure"];for(var y=0;y<C.length;y++){if(u[C[y]]){z[C[y]]=u[C[y]]}}var t=j(B,x,z);p.cookie=t;return x},has:function(u){u=m(u);var x=p.cookie,w=x.indexOf(u+"="),t=w+u.length+1,v=x.substring(0,u.length);return((!w&&u!=v)||w<0)?false:true},get:function(v){v=m(v);var y=p.cookie,x=y.indexOf(v+"="),t=x+v.length+1,w=y.substring(0,v.length),u;if((!x&&v!=w)||x<0){return null}u=y.indexOf(";",t);if(u<0){u=y.length}return l(y.substring(t,u))},remove:function(t){var v=n.get(t),u={expires:q};p.cookie=j(t,"",u);return v},keys:function(){var y=p.cookie,x=y.split("; "),u,w,v=[];for(var t=0;t<x.length;t++){w=x[t].split("=");v.push(l(w[0]))}return v},all:function(){var y=p.cookie,x=y.split("; "),u,w,v=[];for(var t=0;t<x.length;t++){w=x[t].split("=");v.push([l(w[0]),l(w[1])])}return v},version:"0.2.1",enabled:false};n.enabled=o.call(n);return n}());var c=(function(){if(Array.prototype.indexOf){return function(j,k){return Array.prototype.indexOf.call(j,k)}}else{return function(o,p){var n,m;for(var k=0,j=o.length;k<j;k++){if(o[k]==p){return k}}return -1}}})();e=function(){};g=function(j){return"PS"+j.replace(/_/g,"__").replace(/ /g,"_s")};var a={search_order:["localstorage","globalstorage","gears","cookie","ie","flash"],name_re:/^[a-z][a-z0-9_ \-]+$/i,methods:["init","get","set","remove","load","save","iterate"],sql:{version:"1",create:"CREATE TABLE IF NOT EXISTS persist_data (k TEXT UNIQUE NOT NULL PRIMARY KEY, v TEXT NOT NULL)",get:"SELECT v FROM persist_data WHERE k = ?",set:"INSERT INTO persist_data(k, v) VALUES (?, ?)",remove:"DELETE FROM persist_data WHERE k = ?",keys:"SELECT * FROM persist_data"},flash:{div_id:"_persist_flash_wrap",id:"_persist_flash",path:"persist.swf",size:{w:1,h:1},params:{autostart:true}}};b={gears:{size:-1,test:function(){return(window.google&&window.google.gears)?true:false},methods:{init:function(){var j;j=this.db=google.gears.factory.create("beta.database");j.open(g(this.name));j.execute(a.sql.create).close()},get:function(l){var m,n=a.sql.get;var j=this.db;var k;j.execute("BEGIN").close();m=j.execute(n,[l]);k=m.isValidRow()?m.field(0):null;m.close();j.execute("COMMIT").close();return k},set:function(m,p){var k=a.sql.remove,o=a.sql.set,n;var j=this.db;var l;j.execute("BEGIN").close();j.execute(k,[m]).close();j.execute(o,[m,p]).close();j.execute("COMMIT").close();return p},remove:function(l){var n=a.sql.get,p=a.sql.remove,m,o=null,j=false;var k=this.db;k.execute("BEGIN").close();k.execute(p,[l]).close();k.execute("COMMIT").close();return true},iterate:function(m,l){var k=a.sql.keys;var n;var j=this.db;n=j.execute(k);while(n.isValidRow()){m.call(l||this,n.field(0),n.field(1));n.next()}n.close()}}},globalstorage:{size:5*1024*1024,test:function(){if(window.globalStorage){var j="127.0.0.1";if(this.o&&this.o.domain){j=this.o.domain}try{var l=globalStorage[j];return true}catch(k){if(window.console&&window.console.warn){console.warn("globalStorage exists, but couldn't use it because your browser is running on domain:",j)}return false}}else{return false}},methods:{key:function(j){return g(this.name)+g(j)},init:function(){this.store=globalStorage[this.o.domain]},get:function(j){j=this.key(j);return this.store.getItem(j)},set:function(j,k){j=this.key(j);this.store.setItem(j,k);return k},remove:function(j){var k;j=this.key(j);k=this.store.getItem[j];this.store.removeItem(j);return k}}},localstorage:{size:-1,test:function(){try{if(window.localStorage&&window.localStorage.setItem("persistjs_test_local_storage",null)==undefined){window.localStorage.removeItem("persistjs_test_local_storage");if(/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){var k=RegExp.$1;if(k>=9){return true}if(window.location.protocol=="file:"){return false}}else{return true}}else{return false}return window.localStorage?true:false}catch(j){return false}},methods:{key:function(j){return this.name+">"+j},init:function(){this.store=localStorage},get:function(j){j=this.key(j);return this.store.getItem(j)},set:function(j,k){j=this.key(j);this.store.setItem(j,k);return k},remove:function(j){var k;j=this.key(j);k=this.store.getItem(j);this.store.removeItem(j);return k},iterate:function(o,n){var j=this.store,m,p;for(var k=0;k<j.length;k++){m=j.key(k);p=m.split(">");if((p.length==2)&&(p[0]==this.name)){o.call(n||this,p[1],j.getItem(m))}}}}},ie:{prefix:"_persist_data-",size:64*1024,test:function(){return window.ActiveXObject?true:false},make_userdata:function(k){var j=document.createElement("div");j.id=k;j.style.display="none";j.addBehavior("#default#userdata");document.body.appendChild(j);return j},methods:{init:function(){var j=b.ie.prefix+g(this.name);this.el=b.ie.make_userdata(j);if(this.o.defer){this.load()}},get:function(j){var k;j=g(j);if(!this.o.defer){this.load()}k=this.el.getAttribute(j);return k},set:function(j,k){j=g(j);this.el.setAttribute(j,k);if(!this.o.defer){this.save()}return k},remove:function(j){var k;j=g(j);if(!this.o.defer){this.load()}k=this.el.getAttribute(j);this.el.removeAttribute(j);if(!this.o.defer){this.save()}return k},load:function(){this.el.load(g(this.name))},save:function(){this.el.save(g(this.name))}}},cookie:{delim:":",size:4000,test:function(){return d.Cookie.enabled?true:false},methods:{key:function(j){return this.name+b.cookie.delim+j},get:function(j,k){var l;j=this.key(j);l=f.get(j);return l},set:function(j,l,k){j=this.key(j);f.set(j,l,this.o);return l},remove:function(j,k){var k;j=this.key(j);k=f.remove(j);return k}}},flash:{test:function(){try{if(!swfobject){return false}}catch(k){return false}var j=swfobject.getFlashPlayerVersion().major;return(j>=8)?true:false},methods:{init:function(){if(!b.flash.el){var l,m,k,j=a.flash;m=document.createElement("div");m.id=j.div_id;k=document.createElement("div");k.id=j.id;m.appendChild(k);document.body.appendChild(m);b.flash.el=swfobject.createSWF({id:j.id,data:this.o.swf_path||j.path,width:j.size.w,height:j.size.h},j.params,j.id)}this.el=b.flash.el},get:function(j){var k;j=g(j);k=this.el.get(this.name,j);return k},set:function(k,l){var j;k=g(k);j=this.el.set(this.name,k,l);return j},remove:function(j){var k;j=g(j);k=this.el.remove(this.name,j);return k}}}};h=function(){var n,j,p,r,s=a.methods,t=a.search_order;for(var q=0,o=s.length;q<o;q++){d.Store.prototype[s[q]]=e}d.type=null;d.size=-1;for(var m=0,k=t.length;!d.type&&m<k;m++){p=b[t[m]];if(p.test()){d.type=t[m];d.size=p.size;for(r in p.methods){d.Store.prototype[r]=p.methods[r]}}}d._init=true};d={VERSION:i,type:null,size:0,add:function(j){b[j.id]=j;a.search_order=[j.id].concat(a.search_order);h()},remove:function(k){var j=c(a.search_order,k);if(j<0){return}a.search_order.splice(j,1);delete b[k];h()},Cookie:f,Store:function(j,k){if(!a.name_re.exec(j)){throw new Error("Invalid name")}if(!d.type){throw new Error("No suitable storage found")}k=k||{};this.name=j;k.domain=k.domain||location.hostname||"localhost";k.domain=k.domain.replace(/:\d+$/,"");k.domain=(k.domain=="localhost")?"":k.domain;this.o=k;k.expires=k.expires||365*2;k.path=k.path||"/";if(this.o.search_order){a.search_order=this.o.search_order;h()}this.init()}};h();return d})();
var layoutStore = new Persist.Store("LayoutProperties");
// tell Layout that the state plugin is available
$.layout.plugins.stateManagement = true;
Expand Down
Loading

0 comments on commit a910b97

Please sign in to comment.