-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHypeStateKit.min.js
7 lines (7 loc) · 1.23 KB
/
HypeStateKit.min.js
1
2
3
4
5
6
7
/*
Hype StateKit.
copyright (c) 2018 Max Ziebell, (https://maxziebell.de). MIT-license
*/
!1==="HypeStateKit"in window&&(window.HypeStateKit=function(){var c=function(a){if(a)return a=localStorage.getItem(a),null==a?null:JSON.parse(a)},d=function(a,b){a&&localStorage.setItem(a,JSON.stringify(b))},e=function(a){a&&localStorage.removeItem(a)},f=function(a){e(a+"@"+window.location.href)};!1==="HYPE_eventListeners"in window&&(window.HYPE_eventListeners=[]);window.HYPE_eventListeners.push({type:"HypeDocumentLoad",callback:function(a,b,g){a.loadState=function(a){return c(this.documentName()+
"->"+a)};a.saveState=function(a,b){d(this.documentName()+"->"+a,b)};a.removeState=function(a){return e(this.documentName()+"->"+a)};a.loadPageState=function(a){a=this.documentName()+"->"+a;return c(a+"@"+window.location.href)};a.savePageState=function(a,b){var c=this.documentName()+"->"+a;d(c+"@"+window.location.href,b)};a.removePageState=function(a){return f(this.documentName()+"->"+a)};return!0}});return{version:"1.1",loadState:c,saveState:d,loadPageState:c,savePageState:d,removeState:e,removePageState:f,
clearPageState:function(){var a=window.location.href,b;for(b in localStorage)-1<b.indexOf("@"+a)&&e(b)},clear:function(){localStorage.clear()}}}());