Minify ALS

revert-117-master
Gregory Pike 11 years ago
parent 0405741d0d
commit ee9c6d3f6f

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

@ -9,7 +9,7 @@ var DemoCtrl = function($scope, localStorageService) {
$scope.storageType = 'Local storage';
if (!localStorageService.isSupported()) {
if (!localStorageService.isSupported) {
$scope.storageType = 'Cookie';
}

@ -131,7 +131,7 @@ var YourCtrl = function($scope, localStorageService, ...) {
<!-- JAVASCRIPT -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
<script src="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js"></script>
<script src="../angular-local-storage.js"></script>
<script src="../angular-local-storage.min.js"></script>
<script src="demo-app.js"></script>
</body>
</html>