From 91e9e0bec9077441a8165853349149942a71f524 Mon Sep 17 00:00:00 2001 From: Romain Sertelon Date: Wed, 29 Jan 2014 11:47:58 +0100 Subject: [PATCH 1/2] Use AngularJS wrappers Fixes #54 by using and --- angular-local-storage.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/angular-local-storage.js b/angular-local-storage.js index ca92606..9a4af4f 100644 --- a/angular-local-storage.js +++ b/angular-local-storage.js @@ -63,7 +63,7 @@ angularLocalStorage.provider('localStorageService', function(){ // Checks the browser to see if local storage is supported var browserSupportsLocalStorage = (function () { try { - var supported = ('localStorage' in window && window['localStorage'] !== null); + var supported = ('localStorage' in $window && $window['localStorage'] !== null); // When Safari (OS X or iOS) is in private browsing mode, it appears as though localStorage // is available, but trying to call .setItem throws an exception. @@ -224,8 +224,8 @@ angularLocalStorage.provider('localStorageService', function(){ var browserSupportsCookies = function() { try { return navigator.cookieEnabled || - ("cookie" in document && (document.cookie.length > 0 || - (document.cookie = "test").indexOf.call(document.cookie, "test") > -1)); + ("cookie" in $document && ($document.cookie.length > 0 || + ($document.cookie = "test").indexOf.call($document.cookie, "test") > -1)); } catch (e) { $rootScope.$broadcast('LocalStorageModule.notification.error', e.message); return false; @@ -260,7 +260,7 @@ angularLocalStorage.provider('localStorageService', function(){ expiry = "; expires=" + expiryDate.toGMTString(); } if (!!key) { - document.cookie = prefix + key + "=" + encodeURIComponent(value) + expiry + "; path="+cookie.path; + $document.cookie = prefix + key + "=" + encodeURIComponent(value) + expiry + "; path="+cookie.path; } } catch (e) { $rootScope.$broadcast('LocalStorageModule.notification.error',e.message); @@ -277,7 +277,7 @@ angularLocalStorage.provider('localStorageService', function(){ return false; } - var cookies = document.cookie.split(';'); + var cookies = $document.cookie.split(';'); for(var i=0;i < cookies.length;i++) { var thisCookie = cookies[i]; while (thisCookie.charAt(0)===' ') { @@ -297,7 +297,7 @@ angularLocalStorage.provider('localStorageService', function(){ var clearAllFromCookies = function () { var thisCookie = null, thisKey = null; var prefixLength = prefix.length; - var cookies = document.cookie.split(';'); + var cookies = $document.cookie.split(';'); for(var i = 0; i < cookies.length; i++) { thisCookie = cookies[i]; From 6858ddc4df8d5777f250bbbb54123655ebcd26da Mon Sep 17 00:00:00 2001 From: Romain Sertelon Date: Thu, 30 Jan 2014 08:41:53 +0100 Subject: [PATCH 2/2] Injects $window and $document --- angular-local-storage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/angular-local-storage.js b/angular-local-storage.js index 9a4af4f..16dc0d9 100644 --- a/angular-local-storage.js +++ b/angular-local-storage.js @@ -49,7 +49,7 @@ angularLocalStorage.provider('localStorageService', function(){ }; }; - this.$get = ['$rootScope', function($rootScope){ + this.$get = ['$rootScope', '$window', '$document', function($rootScope, $window, $document){ var prefix = this.prefix; var cookie = this.cookie;