f7a4f7b47122b97b446ee154694107218ef976d6
[motion2.git] / snippet / 3.1.0 / scripts / vendor-angular-local-storage.js
1 /*! For license information please see vendor-angular-local-storage.js.LICENSE.txt */
2 (self.webpackChunkmotion_chat=self.webpackChunkmotion_chat||[]).push([["vendor-angular-local-storage"],{"./node_modules/angular-local-storage/dist/angular-local-storage.js":()=>{var e,t,o,r,n,i,a,s,c;window,e=window.angular,t=e.isDefined,o=e.isUndefined,r=e.isNumber,n=e.isObject,i=e.isArray,a=e.isString,s=e.extend,c=e.toJson,e.module("LocalStorageModule",[]).provider("localStorageService",(function(){this.prefix="ls",this.storageType="localStorage",this.cookie={expiry:30,path:"/",secure:!1},this.defaultToCookie=!0,this.notify={setItem:!0,removeItem:!1},this.setPrefix=function(e){return this.prefix=e,this},this.setStorageType=function(e){return this.storageType=e,this},this.setDefaultToCookie=function(e){return this.defaultToCookie=!!e,this},this.setStorageCookie=function(e,t,o){return this.cookie.expiry=e,this.cookie.path=t,this.cookie.secure=o,this},this.setStorageCookieDomain=function(e){return this.cookie.domain=e,this},this.setNotify=function(e,t){return this.notify={setItem:e,removeItem:t},this},this.$get=["$rootScope","$window","$document","$parse","$timeout",function(e,u,l,f,g){var d,h=this,y=h.prefix,m=h.cookie,p=h.notify,T=h.storageType;l?l[0]&&(l=l[0]):l=document,"."!==y.substr(-1)&&(y=y?y+".":"");var v=function(e){return y+e},S=function(e){return e.replace(new RegExp("^"+y,"g"),"")},k=function(){try{var t=T in u&&null!==u[T],o=v("__"+Math.round(1e7*Math.random()));return t&&((d=u[T]).setItem(o,""),d.removeItem(o)),t}catch(t){return h.defaultToCookie&&(T="cookie"),e.$broadcast("LocalStorageModule.notification.error",t.message),!1}},b=k(),O=function(t,r,n){var i=x();try{if(R(n),r=o(r)?null:c(r),!b&&h.defaultToCookie||"cookie"===h.storageType)return b||e.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),p.setItem&&e.$broadcast("LocalStorageModule.notification.setitem",{key:t,newvalue:r,storageType:"cookie"}),M(t,r);try{d&&d.setItem(v(t),r),p.setItem&&e.$broadcast("LocalStorageModule.notification.setitem",{key:t,newvalue:r,storageType:h.storageType})}catch(o){return e.$broadcast("LocalStorageModule.notification.error",o.message),M(t,r)}return!0}finally{R(i)}},L=function(t,o){var r=x();try{if(R(o),!b&&h.defaultToCookie||"cookie"===h.storageType)return b||e.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),w(t);var n=d?d.getItem(v(t)):null;if(!n||"null"===n)return null;try{return JSON.parse(n)}catch(e){return n}}finally{R(r)}},$=function(){var t=x();try{var o,r,n=0;for(arguments.length>=1&&("localStorage"===arguments[arguments.length-1]||"sessionStorage"===arguments[arguments.length-1])&&(n=1,R(arguments[arguments.length-1])),o=0;o<arguments.length-n;o++)if(r=arguments[o],!b&&h.defaultToCookie||"cookie"===h.storageType)b||e.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),p.removeItem&&e.$broadcast("LocalStorageModule.notification.removeitem",{key:r,storageType:"cookie"}),C(r);else try{d.removeItem(v(r)),p.removeItem&&e.$broadcast("LocalStorageModule.notification.removeitem",{key:r,storageType:h.storageType})}catch(t){e.$broadcast("LocalStorageModule.notification.error",t.message),C(r)}}finally{R(t)}},E=function(){try{return u.navigator.cookieEnabled||"cookie"in l&&(l.cookie.length>0||(l.cookie="test").indexOf.call(l.cookie,"test")>-1)}catch(t){return e.$broadcast("LocalStorageModule.notification.error",t.message),!1}}(),M=function(t,a,s,u){if(o(a))return!1;if((i(a)||n(a))&&(a=c(a)),!E)return e.$broadcast("LocalStorageModule.notification.error","COOKIES_NOT_SUPPORTED"),!1;try{var f="",g=new Date,d="";if(null===a?(g.setTime(g.getTime()+-864e5),f="; expires="+g.toGMTString(),a=""):r(s)&&0!==s?(g.setTime(g.getTime()+24*s*60*60*1e3),f="; expires="+g.toGMTString()):0!==m.expiry&&(g.setTime(g.getTime()+24*m.expiry*60*60*1e3),f="; expires="+g.toGMTString()),t){var h="; path="+m.path;m.domain&&(d="; domain="+m.domain),"boolean"==typeof u?!0===u&&(d+="; secure"):!0===m.secure&&(d+="; secure"),l.cookie=v(t)+"="+encodeURIComponent(a)+f+h+d}}catch(t){return e.$broadcast("LocalStorageModule.notification.error",t.message),!1}return!0},w=function(t){if(!E)return e.$broadcast("LocalStorageModule.notification.error","COOKIES_NOT_SUPPORTED"),!1;for(var o=l.cookie&&l.cookie.split(";")||[],r=0;r<o.length;r++){for(var n=o[r];" "===n.charAt(0);)n=n.substring(1,n.length);if(0===n.indexOf(v(t)+"=")){var i=decodeURIComponent(n.substring(y.length+t.length+1,n.length));try{var a=JSON.parse(i);return"number"==typeof a?i:a}catch(e){return i}}}return null},C=function(e){M(e,null)},_=function(){for(var e=null,t=y.length,o=l.cookie.split(";"),r=0;r<o.length;r++){for(e=o[r];" "===e.charAt(0);)e=e.substring(1,e.length);var n=e.substring(t,e.indexOf("="));C(n)}},x=function(){return T},R=function(e){return e&&T!==e&&(T=e,b=k()),b};function I(t){if(t||(t=u.event),p.setItem&&a(t.key)&&function(e){return 0===e.indexOf(y)}(t.key)){var o=S(t.key);g((function(){e.$broadcast("LocalStorageModule.notification.changed",{key:o,newvalue:t.newValue,storageType:h.storageType})}))}}return b&&(u.addEventListener?(u.addEventListener("storage",I,!1),e.$on("$destroy",(function(){u.removeEventListener("storage",I)}))):u.attachEvent&&(u.attachEvent("onstorage",I),e.$on("$destroy",(function(){u.detachEvent("onstorage",I)})))),{isSupported:b,getStorageType:x,setStorageType:R,setPrefix:function(e){y=e},set:O,add:O,get:L,keys:function(t){var o=x();try{if(R(t),!b)return e.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),[];var r=y.length,n=[];for(var i in d)if(i.substr(0,r)===y)try{n.push(i.substr(r))}catch(t){return e.$broadcast("LocalStorageModule.notification.error",t.Description),[]}return n}finally{R(o)}},remove:$,clearAll:function(t,o){var r=x();try{R(o);var n=y?new RegExp("^"+y):new RegExp,i=t?new RegExp(t):new RegExp;if(!b&&h.defaultToCookie||"cookie"===h.storageType)return b||e.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),_();if(!b&&!h.defaultToCookie)return!1;var a=y.length;for(var s in d)if(n.test(s)&&i.test(s.substr(a)))try{$(s.substr(a))}catch(t){return e.$broadcast("LocalStorageModule.notification.error",t.message),_()}return!0}finally{R(r)}},bind:function(e,o,r,i,a){var c=L(i=i||o,a);return null===c&&t(r)?c=r:n(c)&&n(r)&&(c=s(c,r)),f(o).assign(e,c),e.$watch(o,(function(e){O(i,e,a)}),n(e[o]))},deriveKey:v,underiveKey:S,length:function(e){var t=x();try{R(e);for(var o=0,r=u[T],n=0;n<r.length;n++)0===r.key(n).indexOf(y)&&o++;return o}finally{R(t)}},defaultToCookie:this.defaultToCookie,cookie:{isSupported:E,set:M,add:M,get:w,remove:C,clearAll:_}}}]}))}}]);
3 //# sourceMappingURL=vendor-angular-local-storage.js.map