-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathangular-webstorage.min.js
1 lines (1 loc) · 6.21 KB
/
angular-webstorage.min.js
1
var webStorageModule=angular.module("webStorageModule",[]);webStorageModule.constant("defaultSettings",{prefix:"",order:["local","session","memory"],errorName:"webStorage.notification.error",testKey:"webStorage.test.key"}),webStorageModule.factory("webStorage",["$rootScope","defaultSettings",function(a,b){"use strict";function n(a,b){return console.warn(d),q(a,b)}function o(a,b){return console.warn(d),r(a,b)}function p(a,b){return console.warn(d),s(a,b)}function q(a,b){if(f){try{localStorage.setItem(k+a,JSON.stringify(b))}catch(c){return N(c)}return!0}return!1}function r(a,b){if(g){try{sessionStorage.setItem(k+a,JSON.stringify(b))}catch(c){return N(c)}return!0}return!1}function s(a,b){return l[a]=b,!0}function t(a){if(f)try{var b=localStorage.getItem(k+a);return b&&JSON.parse(b)}catch(c){return N(c),null}return null}function u(a){if(g)try{var b=sessionStorage.getItem(k+a);return b&&JSON.parse(b)}catch(c){return N(c),null}return null}function v(a){return a in l?l[a]:null}function w(a){return null!==t(a)}function x(a){return null!==u(a)}function y(a){return null!==v(a)}function z(a){return f?localStorage.key(a):null}function A(a){return g?sessionStorage.key(a):null}function B(a){var b=0;for(var c in l)if(l.hasOwnProperty(c)){if(a===b)return c;if(b+=1,b>a)return null}return null}function C(){return f?localStorage.length:0}function D(){return g?sessionStorage.length:0}function E(){if(Object.keys)return Object.keys(l).length;var a=0;for(var b in l)l.hasOwnProperty(b)&&(a+=1);return a}function F(a){if(f){try{localStorage.removeItem(k+a)}catch(b){return N(b)}return!0}return!1}function G(a){if(g){try{sessionStorage.removeItem(k+a)}catch(b){return N(b)}return!0}return!1}function H(a){return delete l[a],!0}function I(){if(!f)return!1;if(k){var a=k.length;try{for(var b in localStorage)b.substr(0,a)===k&&localStorage.removeItem(b)}catch(c){return N(c)}return!0}try{localStorage.clear()}catch(c){return N(c)}return!0}function J(){if(!g)return!1;if(k){var a=k.length;try{for(var b in sessionStorage)b.substr(0,a)===k&&sessionStorage.removeItem(b)}catch(c){return N(c)}return!0}try{sessionStorage.clear()}catch(c){return N(c)}return!0}function K(){return l={},!0}function L(){O();try{return localStorage.setItem(k+b.testKey,b.testKey),localStorage.removeItem(k+b.testKey),!0}catch(a){return!1}}function M(){P();try{return sessionStorage.setItem(k+b.testKey,b.testKey),sessionStorage.removeItem(k+b.testKey),!0}catch(a){return!1}}function N(b){return a.$broadcast(e,b.title+": "+b.message),!1}function O(){try{window.localStorage||(window.localStorage={getItem:function(a){return a&&this.hasOwnProperty(a)?unescape(document.cookie.replace(new RegExp("(?:^|.*;\\s*)"+escape(a).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*"),"$1")):null},key:function(a){return unescape(document.cookie.replace(/\s*\=(?:.(?!;))*$/,"").split(/\s*\=(?:[^;](?!;))*[^;]?;\s*/)[a])},setItem:function(a,b){a&&(document.cookie=escape(a)+"="+escape(b)+"; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/",this.length=document.cookie.match(/\=/g).length)},length:0,removeItem:function(a){a&&this.hasOwnProperty(a)&&(document.cookie=escape(a)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/",this.length--)},hasOwnProperty:function(a){return new RegExp("(?:^|;\\s*)"+escape(a).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(document.cookie)}},window.localStorage.length=(document.cookie.match(/\=/g)||window.localStorage).length,h=!0)}catch(a){}}function P(){try{window.sessionStorage||(window.sessionStorage={getItem:function(a){return a&&this.hasOwnProperty(a)?unescape(document.cookie.replace(new RegExp("(?:^|.*;\\s*)"+escape(a).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*"),"$1")):null},key:function(a){return unescape(document.cookie.replace(/\s*\=(?:.(?!;))*$/,"").split(/\s*\=(?:[^;](?!;))*[^;]?;\s*/)[a])},setItem:function(a,b){a&&(document.cookie=escape(a)+"="+escape(b)+"; path=/",this.length=document.cookie.match(/\=/g).length)},length:0,removeItem:function(a){a&&this.hasOwnProperty(a)&&(document.cookie=escape(a)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/",this.length--)},hasOwnProperty:function(a){return new RegExp("(?:^|;\\s*)"+escape(a).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(document.cookie)}},window.sessionStorage.length=(document.cookie.match(/\=/g)||window.sessionStorage).length,i=!0)}catch(a){}}function Q(a){var b=h;return a===!0&&h&&(window.localStorage=null,h=!1),b}function R(a){var b=i;return a===!0&&i&&(window.sessionStorage=null,h=!1),b}var c="undefined",d="angular-webstorage.js -- `add()` had been deprecated, use `set()` instead",e=b.errorName,f=L(),g=M(),h=!1,i=!1,j=b.order,k=b.prefix,l={},m={isSupported:f||g,local:{isSupported:f,add:n,set:q,get:t,has:w,key:z,length:C,remove:F,clear:I,isPolyfilled:Q},session:{isSupported:g,add:o,set:r,get:u,has:x,key:A,length:D,remove:G,clear:J,isPolyfilled:R},memory:{isSupported:!0,add:p,set:s,get:v,has:y,key:B,length:E,remove:H,clear:K,isPolyfilled:!1}};return m.add=function(a,b,c){return console.warn(d),m.set(a,b,c)},m.set=function(a,b,d){d=typeof d!==c?!!d:!1;for(var e=!1,f=j.length,g=0;f>g;++g){var h=m[j[g]];if(h.isSupported&&(e=h.set(a,b)||e,!d))return e}return e},m.get=function(a,b){b=typeof b!==c?!!b:!0;for(var d=j.length,e=0;d>e;++e){var f=m[j[e]];if(f.isSupported){var g=f.get(a);if(!b||null!==g)return g}}return null},m.has=function(a,b){return null!==m.get(a,b)},m.key=function(a,b){b=typeof b!==c?!!b:!0;for(var d=j.length,e=0;d>e;++e){var f=m[j[e]];if(f.isSupported){var g=f.key(a);if(!b||null!==g)return g}}return null},m.length=function(a){a=typeof a!==c?!!a:!0;for(var b=j.length,d=0;b>d;++d){var e=m[j[d]];if(e.isSupported){var f=e.length();if(!a||0!==f)return f}}return 0},m.remove=function(a,b){b=typeof b!==c?!!b:!0;for(var d=!1,e=j.length,f=0;e>f;++f){var g=m[j[f]];if(g.isSupported&&(d=g.remove(a)||d,!b))return d}return d},m.clear=function(a){a=typeof a!==c?!!a:!0;for(var b=!1,d=j.length,e=0;d>e;++e){var f=m[j[e]];if(f.isSupported&&(b=f.clear()||b,!a))return b}return b},m.errorName=function(a){var b=e;if(typeof a!==c){if("string"!=typeof a)return!1;e=a}return b},m.order=function(a){var b=angular.copy(j);if(typeof a!==c){j=[];for(var d in a)/^(local|session|memory)$/.test(a[d])&&j.push(a[d])}return b},m.prefix=function(a){var b=k;if(typeof a!==c){if("string"!=typeof a)return!1;k=a}return b},m}]);