From 9e3537bfd513b23cfb184ab93b5d07183a365dc4 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Thu, 14 Aug 2014 08:55:24 +0300 Subject: [PATCH 1/4] fix(localStorageService): fix usage of 'this' keyword on closures --- angular-local-storage.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/angular-local-storage.js b/angular-local-storage.js index d60b122..af4f8ce 100644 --- a/angular-local-storage.js +++ b/angular-local-storage.js @@ -4,7 +4,7 @@ var angularLocalStorage = angular.module('LocalStorageModule', []); angularLocalStorage.provider('localStorageService', function() { - + // You should set a prefix to avoid overwriting any local storage variables from the rest of your app // e.g. localStorageServiceProvider.setPrefix('youAppName'); // With provider you can use config as this: @@ -65,11 +65,11 @@ angularLocalStorage.provider('localStorageService', function() { this.$get = ['$rootScope', '$window', '$document', function($rootScope, $window, $document) { - - var prefix = this.prefix; - var cookie = this.cookie; - var notify = this.notify; - var storageType = this.storageType; + var self = this; + var prefix = self.prefix; + var cookie = self.cookie; + var notify = self.notify; + var storageType = self.storageType; var webStorage; // When Angular's $document is not available @@ -110,7 +110,7 @@ angularLocalStorage.provider('localStorageService', function() { return false; } }()); - + // Directly adds a value to local storage @@ -119,7 +119,7 @@ angularLocalStorage.provider('localStorageService', function() { var addToLocalStorage = function (key, value) { // If this browser does not support local storage use cookies - if (!browserSupportsLocalStorage || this.storageType === 'cookie') { + if (!browserSupportsLocalStorage || self.storageType === 'cookie') { $rootScope.$broadcast('LocalStorageModule.notification.warning', 'LOCAL_STORAGE_NOT_SUPPORTED'); if (notify.setItem) { $rootScope.$broadcast('LocalStorageModule.notification.setitem', {key: key, newvalue: value, storageType: 'cookie'}); @@ -138,7 +138,7 @@ angularLocalStorage.provider('localStorageService', function() { } if (webStorage) {webStorage.setItem(deriveQualifiedKey(key), value)}; if (notify.setItem) { - $rootScope.$broadcast('LocalStorageModule.notification.setitem', {key: key, newvalue: value, storageType: this.storageType}); + $rootScope.$broadcast('LocalStorageModule.notification.setitem', {key: key, newvalue: value, storageType: self.storageType}); } } catch (e) { $rootScope.$broadcast('LocalStorageModule.notification.error', e.message); @@ -151,7 +151,7 @@ angularLocalStorage.provider('localStorageService', function() { // Example use: localStorageService.get('library'); // returns 'angular' var getFromLocalStorage = function (key) { - if (!browserSupportsLocalStorage || this.storageType === 'cookie') { + if (!browserSupportsLocalStorage || self.storageType === 'cookie') { $rootScope.$broadcast('LocalStorageModule.notification.warning','LOCAL_STORAGE_NOT_SUPPORTED'); return getFromCookies(key); } @@ -184,7 +184,7 @@ angularLocalStorage.provider('localStorageService', function() { try { webStorage.removeItem(deriveQualifiedKey(key)); if (notify.removeItem) { - $rootScope.$broadcast('LocalStorageModule.notification.removeitem', {key: key, storageType: this.storageType}); + $rootScope.$broadcast('LocalStorageModule.notification.removeitem', {key: key, storageType: self.storageType}); } } catch (e) { $rootScope.$broadcast('LocalStorageModule.notification.error', e.message); @@ -335,7 +335,7 @@ angularLocalStorage.provider('localStorageService', function() { var cookies = $document.cookie.split(';'); for(var i = 0; i < cookies.length; i++) { thisCookie = cookies[i]; - + while (thisCookie.charAt(0) === ' ') { thisCookie = thisCookie.substring(1, thisCookie.length); } From ee19f3dac64b1d39f30abfd29558e4ee189b63e9 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Thu, 14 Aug 2014 08:56:10 +0300 Subject: [PATCH 2/4] fix(bower): update version to 0.0.7 --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index acd267c..4ae53d9 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-local-storage", - "version": "0.0.6", + "version": "0.0.7", "homepage": "http://gregpike.net/demos/angular-local-storage/demo.html", "authors": [ "grevory " From f05c83cd74dd98c58e0c5754d48d85b213c8b3fb Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Thu, 14 Aug 2014 08:56:41 +0300 Subject: [PATCH 3/4] fix(package): update version to 0.0.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 174b3b7..107de2f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-local-storage", - "version": "0.0.6", + "version": "0.0.7", "description": "An Angular module that gives you access to the browsers local storage", "main": "angular-local-storage.js", "scripts": { From 642f1fe7fca7294e35750f6c38fab917c178a32a Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Thu, 14 Aug 2014 09:02:09 +0300 Subject: [PATCH 4/4] fix(dist): uglify angular-local-storage --- angular-local-storage.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/angular-local-storage.min.js b/angular-local-storage.min.js index d62b936..0c66ac5 100644 --- a/angular-local-storage.min.js +++ b/angular-local-storage.min.js @@ -1 +1 @@ -(function(){"use strict";var a=angular.module("LocalStorageModule",[]);a.provider("localStorageService",function(){this.prefix="ls",this.storageType="localStorage",this.cookie={expiry:30,path:"/"},this.notify={setItem:!0,removeItem:!1},this.setPrefix=function(a){this.prefix=a},this.setStorageType=function(a){this.storageType=a},this.setStorageCookie=function(a,b){this.cookie={expiry:a,path:b}},this.setStorageCookieDomain=function(a){this.cookie.domain=a},this.setNotify=function(a,b){this.notify={setItem:a,removeItem:b}},this.$get=["$rootScope","$window","$document",function(a,b,c){var d,e=this.prefix,f=this.cookie,g=this.notify,h=this.storageType;c||(c=document),"."!==e.substr(-1)&&(e=e?e+".":"");var i=function(a){return e+a},j=function(){try{var c=h in b&&null!==b[h],e=i("__"+Math.round(1e7*Math.random()));return c&&(d=b[h],d.setItem(e,""),d.removeItem(e)),c}catch(f){return h="cookie",a.$broadcast("LocalStorageModule.notification.error",f.message),!1}}(),k=function(b,c){if(!j)return a.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),g.setItem&&a.$broadcast("LocalStorageModule.notification.setitem",{key:b,newvalue:c,storageType:"cookie"}),q(b,c);"undefined"==typeof c&&(c=null);try{(angular.isObject(c)||angular.isArray(c))&&(c=angular.toJson(c)),d&&d.setItem(i(b),c),g.setItem&&a.$broadcast("LocalStorageModule.notification.setitem",{key:b,newvalue:c,storageType:this.storageType})}catch(e){return a.$broadcast("LocalStorageModule.notification.error",e.message),q(b,c)}return!0},l=function(b){if(!j)return a.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),r(b);var c=d?d.getItem(i(b)):null;return c&&"null"!==c?"{"===c.charAt(0)||"["===c.charAt(0)?angular.fromJson(c):c:null},m=function(b){if(!j)return a.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),g.removeItem&&a.$broadcast("LocalStorageModule.notification.removeitem",{key:b,storageType:"cookie"}),s(b);try{d.removeItem(i(b)),g.removeItem&&a.$broadcast("LocalStorageModule.notification.removeitem",{key:b,storageType:this.storageType})}catch(c){return a.$broadcast("LocalStorageModule.notification.error",c.message),s(b)}return!0},n=function(){if(!j)return a.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),!1;var b=e.length,c=[];for(var f in d)if(f.substr(0,b)===e)try{c.push(f.substr(b))}catch(g){return a.$broadcast("LocalStorageModule.notification.error",g.Description),[]}return c},o=function(b){b=b||"";var c=e.slice(0,-1),f=new RegExp(c+"."+b);if(!j)return a.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),t();var g=e.length;for(var h in d)if(f.test(h))try{m(h.substr(g))}catch(i){return a.$broadcast("LocalStorageModule.notification.error",i.message),t()}return!0},p=function(){try{return navigator.cookieEnabled||"cookie"in c&&(c.cookie.length>0||(c.cookie="test").indexOf.call(c.cookie,"test")>-1)}catch(b){return a.$broadcast("LocalStorageModule.notification.error",b.message),!1}},q=function(b,d){if("undefined"==typeof d)return!1;if(!p())return a.$broadcast("LocalStorageModule.notification.error","COOKIES_NOT_SUPPORTED"),!1;try{var e="",g=new Date,h="";if(null===d?(g.setTime(g.getTime()+-864e5),e="; expires="+g.toGMTString(),d=""):0!==f.expiry&&(g.setTime(g.getTime()+24*f.expiry*60*60*1e3),e="; expires="+g.toGMTString()),b){var j="; path="+f.path;f.domain&&(h="; domain="+f.domain),c.cookie=i(b)+"="+encodeURIComponent(d)+e+j+h}}catch(k){return a.$broadcast("LocalStorageModule.notification.error",k.message),!1}return!0},r=function(b){if(!p())return a.$broadcast("LocalStorageModule.notification.error","COOKIES_NOT_SUPPORTED"),!1;for(var d=c.cookie&&c.cookie.split(";")||[],f=0;f0||(c.cookie="test").indexOf.call(c.cookie,"test")>-1)}catch(b){return a.$broadcast("LocalStorageModule.notification.error",b.message),!1}},r=function(b,d){if("undefined"==typeof d)return!1;if(!q())return a.$broadcast("LocalStorageModule.notification.error","COOKIES_NOT_SUPPORTED"),!1;try{var e="",f=new Date,h="";if(null===d?(f.setTime(f.getTime()+-864e5),e="; expires="+f.toGMTString(),d=""):0!==g.expiry&&(f.setTime(f.getTime()+24*g.expiry*60*60*1e3),e="; expires="+f.toGMTString()),b){var i="; path="+g.path;g.domain&&(h="; domain="+g.domain),c.cookie=j(b)+"="+encodeURIComponent(d)+e+i+h}}catch(k){return a.$broadcast("LocalStorageModule.notification.error",k.message),!1}return!0},s=function(b){if(!q())return a.$broadcast("LocalStorageModule.notification.error","COOKIES_NOT_SUPPORTED"),!1;for(var d=c.cookie&&c.cookie.split(";")||[],e=0;e