(function(){"use strict";var n=angular.module("LocalStorageModule",[]);n.provider("localStorageService",function(){this.prefix="ls",this.storageType="localStorage",this.cookie={expiry:30,path:"/"},this.notify={setItem:!0,removeItem:!1},this.setPrefix=function(n){this.prefix=n},this.setStorageType=function(n){this.storageType=n},this.setStorageCookie=function(n,t){this.cookie={expiry:n,path:t}},this.setStorageCookieDomain=function(n){this.cookie.domain=n},this.setNotify=function(n,t){this.notify={setItem:n,removeItem:t}},this.$get=["$rootScope","$window","$document",function(n,t,i){var u,r=this.prefix,o=this.cookie,c=this.notify,s=this.storageType;i||(i=document),"."!==r.substr(-1)&&(r=r?r+".":"");var f=function(n){return r+n},e=function(){try{var i=s in t&&null!==t[s],r=f("__"+Math.round(1e7*Math.random()));return i&&(u=t[s],u.setItem(r,""),u.removeItem(r)),i}catch(e){return s="cookie",n.$broadcast("LocalStorageModule.notification.error",e.message),!1}}(),a=function(t,i){if(!e)return n.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),c.setItem&&n.$broadcast("LocalStorageModule.notification.setitem",{key:t,newvalue:i,storageType:"cookie"}),h(t,i);"undefined"==typeof i&&(i=null);try{(angular.isObject(i)||angular.isArray(i))&&(i=angular.toJson(i)),u&&u.setItem(f(t),i),c.setItem&&n.$broadcast("LocalStorageModule.notification.setitem",{key:t,newvalue:i,storageType:this.storageType})}catch(r){return n.$broadcast("LocalStorageModule.notification.error",r.message),h(t,i)}return!0},y=function(t){if(!e)return n.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),b(t);var i=u?u.getItem(f(t)):null;return i&&"null"!==i?"{"===i.charAt(0)||"["===i.charAt(0)?angular.fromJson(i):i:null},p=function(t){if(!e)return n.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),c.removeItem&&n.$broadcast("LocalStorageModule.notification.removeitem",{key:t,storageType:"cookie"}),l(t);try{u.removeItem(f(t)),c.removeItem&&n.$broadcast("LocalStorageModule.notification.removeitem",{key:t,storageType:this.storageType})}catch(i){return n.$broadcast("LocalStorageModule.notification.error",i.message),l(t)}return!0},k=function(){var t,i,f;if(!e)return n.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),!1;t=r.length,i=[];for(f in u)if(f.substr(0,t)===r)try{i.push(f.substr(t))}catch(o){return n.$broadcast("LocalStorageModule.notification.error",o.Description),[]}return i},d=function(t){var f,o,s,i;if(t=t||"",f=r.slice(0,-1),o=new RegExp(f+"."+t),!e)return n.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),v();s=r.length;for(i in u)if(o.test(i))try{p(i.substr(s))}catch(h){return n.$broadcast("LocalStorageModule.notification.error",h.message),v()}return!0},w=function(){try{return navigator.cookieEnabled||"cookie"in i&&(i.cookie.length>0||(i.cookie="test").indexOf.call(i.cookie,"test")>-1)}catch(t){return n.$broadcast("LocalStorageModule.notification.error",t.message),!1}},h=function(t,r){var h;if("undefined"==typeof r)return!1;if(!w())return n.$broadcast("LocalStorageModule.notification.error","COOKIES_NOT_SUPPORTED"),!1;try{var e="",u=new Date,s="";(null===r?(u.setTime(u.getTime()+-864e5),e="; expires="+u.toGMTString(),r=""):0!==o.expiry&&(u.setTime(u.getTime()+864e5*o.expiry),e="; expires="+u.toGMTString()),t)&&(h="; path="+o.path,o.domain&&(s="; domain="+o.domain),i.cookie=f(t)+"="+encodeURIComponent(r)+e+h+s)}catch(c){return n.$broadcast("LocalStorageModule.notification.error",c.message),!1}return!0},b=function(t){var o,e,u;if(!w())return n.$broadcast("LocalStorageModule.notification.error","COOKIES_NOT_SUPPORTED"),!1;for(o=i.cookie&&i.cookie.split(";")||[],e=0;e<o.length;e++){for(u=o[e];" "===u.charAt(0);)u=u.substring(1,u.length);if(0===u.indexOf(f(t)+"="))return decodeURIComponent(u.substring(r.length+t.length+1,u.length))}return null},l=function(n){h(n,null)},v=function(){for(var f,n=null,e=r.length,u=i.cookie.split(";"),t=0;t<u.length;t++){for(n=u[t];" "===n.charAt(0);)n=n.substring(1,n.length);f=n.substring(e,n.indexOf("=")),l(f)}},g=function(){return s},nt=function(n,t,i){var r=y(t);null===r&&angular.isDefined(i)?r=i:angular.isObject(r)&&angular.isObject(i)&&(r=angular.extend(i,r)),n[t]=r,n.$watchCollection(t,function(n){a(t,n)})};return{isSupported:e,getStorageType:g,set:a,add:a,get:y,keys:k,remove:p,clearAll:d,bind:nt,deriveKey:f,cookie:{set:h,add:h,get:b,remove:l,clearAll:v}}}]})}).call(this)