From 330fc3f28b0591ea35bb1bbed29771c1b945c4d5 Mon Sep 17 00:00:00 2001 From: Sebastian Gronewold Date: Tue, 12 Aug 2014 10:15:02 +0000 Subject: [PATCH 1/4] Added unwrapping of the jquery encapsulated $document variable See http://www.bennadel.com/blog/2630-accessing-document-properties-in-angularjs.htm --- angular-local-storage.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/angular-local-storage.js b/angular-local-storage.js index 0a8ee3f..8ebbe0b 100644 --- a/angular-local-storage.js +++ b/angular-local-storage.js @@ -75,6 +75,10 @@ angularLocalStorage.provider('localStorageService', function() { // When Angular's $document is not available if (!$document) { $document = document; + } else { + // unwrapping the jquery encapsulated document to access cookies + // (see http://www.bennadel.com/blog/2630-accessing-document-properties-in-angularjs.htm) + $document = $document[0]; } // If there is a prefix set in the config lets use that with an appended period for readability From 7ef86fb4a5d12edef3fc0231f22f6e31edd9a08c Mon Sep 17 00:00:00 2001 From: Sebastian Gronewold Date: Tue, 12 Aug 2014 10:33:41 +0000 Subject: [PATCH 2/4] Reverted changes as they have already been pull requested --- angular-local-storage.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/angular-local-storage.js b/angular-local-storage.js index 0a8ee3f..8ebbe0b 100644 --- a/angular-local-storage.js +++ b/angular-local-storage.js @@ -75,6 +75,10 @@ angularLocalStorage.provider('localStorageService', function() { // When Angular's $document is not available if (!$document) { $document = document; + } else { + // unwrapping the jquery encapsulated document to access cookies + // (see http://www.bennadel.com/blog/2630-accessing-document-properties-in-angularjs.htm) + $document = $document[0]; } // If there is a prefix set in the config lets use that with an appended period for readability From e7c465c898f78a7ab8e6f0facfb7718816e0c4ad Mon Sep 17 00:00:00 2001 From: Sebastian Gronewold Date: Tue, 12 Aug 2014 10:34:35 +0000 Subject: [PATCH 3/4] Handling for explicit usage of cookie fallback If the user explicitely set the storage type to cookie also the getFromLlocalStorage and addToLocalStorage method should use the cookie fallback. --- angular-local-storage.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/angular-local-storage.js b/angular-local-storage.js index 8ebbe0b..96a4210 100644 --- a/angular-local-storage.js +++ b/angular-local-storage.js @@ -121,7 +121,7 @@ angularLocalStorage.provider('localStorageService', function() { var addToLocalStorage = function (key, value) { // If this browser does not support local storage use cookies - if (!browserSupportsLocalStorage) { + if (!browserSupportsLocalStorage || this.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'}); @@ -153,7 +153,7 @@ angularLocalStorage.provider('localStorageService', function() { // Example use: localStorageService.get('library'); // returns 'angular' var getFromLocalStorage = function (key) { - if (!browserSupportsLocalStorage) { + if (!browserSupportsLocalStorage || this.storageType === 'cookie') { $rootScope.$broadcast('LocalStorageModule.notification.warning','LOCAL_STORAGE_NOT_SUPPORTED'); return getFromCookies(key); } From 570d7657c4cd49e516a2098e9ba3233090b771ef Mon Sep 17 00:00:00 2001 From: Sebastian Gronewold Date: Tue, 12 Aug 2014 10:37:12 +0000 Subject: [PATCH 4/4] Reverted changes... --- angular-local-storage.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/angular-local-storage.js b/angular-local-storage.js index 96a4210..9850a77 100644 --- a/angular-local-storage.js +++ b/angular-local-storage.js @@ -75,10 +75,6 @@ angularLocalStorage.provider('localStorageService', function() { // When Angular's $document is not available if (!$document) { $document = document; - } else { - // unwrapping the jquery encapsulated document to access cookies - // (see http://www.bennadel.com/blog/2630-accessing-document-properties-in-angularjs.htm) - $document = $document[0]; } // If there is a prefix set in the config lets use that with an appended period for readability