From 0b8be0935af353f5359f3c719506615a720a5ba6 Mon Sep 17 00:00:00 2001 From: Sebastian Gronewold Date: Thu, 14 Aug 2014 18:23:21 +0200 Subject: [PATCH 1/2] Added PHPStorm project files to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 338d9e5..a048522 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ bower_components .DS_Store npm-debug.log *.swp +.idea From f7753704c2c6ca4d53286d8f495150e03ea1b663 Mon Sep 17 00:00:00 2001 From: Sebastian Gronewold Date: Thu, 14 Aug 2014 18:28:35 +0200 Subject: [PATCH 2/2] Cleanuped code for enforced cookie usage In my last pull request I added the first support for handling of the enforced usage of cookies as storage. Now I added this support to the remove function and to the clearAll function. Also I exluded warnings that the browser does not support local storage if the user explicitely wants to use cookies. --- angular-local-storage.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/angular-local-storage.js b/angular-local-storage.js index af4f8ce..f212b16 100644 --- a/angular-local-storage.js +++ b/angular-local-storage.js @@ -62,8 +62,6 @@ angularLocalStorage.provider('localStorageService', function() { }; }; - - this.$get = ['$rootScope', '$window', '$document', function($rootScope, $window, $document) { var self = this; var prefix = self.prefix; @@ -120,7 +118,10 @@ angularLocalStorage.provider('localStorageService', function() { // If this browser does not support local storage use cookies if (!browserSupportsLocalStorage || self.storageType === 'cookie') { - $rootScope.$broadcast('LocalStorageModule.notification.warning', 'LOCAL_STORAGE_NOT_SUPPORTED'); + if (!browserSupportsLocalStorage) { + $rootScope.$broadcast('LocalStorageModule.notification.warning', 'LOCAL_STORAGE_NOT_SUPPORTED'); + } + if (notify.setItem) { $rootScope.$broadcast('LocalStorageModule.notification.setitem', {key: key, newvalue: value, storageType: 'cookie'}); } @@ -152,7 +153,10 @@ angularLocalStorage.provider('localStorageService', function() { var getFromLocalStorage = function (key) { if (!browserSupportsLocalStorage || self.storageType === 'cookie') { - $rootScope.$broadcast('LocalStorageModule.notification.warning','LOCAL_STORAGE_NOT_SUPPORTED'); + if (!browserSupportsLocalStorage) { + $rootScope.$broadcast('LocalStorageModule.notification.warning','LOCAL_STORAGE_NOT_SUPPORTED'); + } + return getFromCookies(key); } @@ -173,8 +177,11 @@ angularLocalStorage.provider('localStorageService', function() { // Remove an item from local storage // Example use: localStorageService.remove('library'); // removes the key/value pair of library='angular' var removeFromLocalStorage = function (key) { - if (!browserSupportsLocalStorage) { - $rootScope.$broadcast('LocalStorageModule.notification.warning', 'LOCAL_STORAGE_NOT_SUPPORTED'); + if (!browserSupportsLocalStorage || self.storageType === 'cookie') { + if (!browserSupportsLocalStorage) { + $rootScope.$broadcast('LocalStorageModule.notification.warning', 'LOCAL_STORAGE_NOT_SUPPORTED'); + } + if (notify.removeItem) { $rootScope.$broadcast('LocalStorageModule.notification.removeitem', {key: key, storageType: 'cookie'}); } @@ -229,8 +236,11 @@ angularLocalStorage.provider('localStorageService', function() { var tempPrefix = prefix.slice(0, -1); var testRegex = new RegExp(tempPrefix + '.' + regularExpression); - if (!browserSupportsLocalStorage) { - $rootScope.$broadcast('LocalStorageModule.notification.warning', 'LOCAL_STORAGE_NOT_SUPPORTED'); + if (!browserSupportsLocalStorage || self.storageType === 'cookie') { + if (!browserSupportsLocalStorage) { + $rootScope.$broadcast('LocalStorageModule.notification.warning', 'LOCAL_STORAGE_NOT_SUPPORTED'); + } + return clearAllFromCookies(); }