4
4
var angularLocalStorage = angular . module ( 'LocalStorageModule' , [ ] ) ;
5
5
6
6
angularLocalStorage . provider ( 'localStorageService' , function ( ) {
7
-
7
+
8
8
// You should set a prefix to avoid overwriting any local storage variables from the rest of your app
9
9
// e.g. localStorageServiceProvider.setPrefix('youAppName');
10
10
// With provider you can use config as this:
@@ -65,11 +65,11 @@ angularLocalStorage.provider('localStorageService', function() {
65
65
66
66
67
67
this . $get = [ '$rootScope' , '$window' , '$document' , function ( $rootScope , $window , $document ) {
68
-
69
- var prefix = this . prefix ;
70
- var cookie = this . cookie ;
71
- var notify = this . notify ;
72
- var storageType = this . storageType ;
68
+ var self = this ;
69
+ var prefix = self . prefix ;
70
+ var cookie = self . cookie ;
71
+ var notify = self . notify ;
72
+ var storageType = self . storageType ;
73
73
var webStorage ;
74
74
75
75
// When Angular's $document is not available
@@ -110,7 +110,7 @@ angularLocalStorage.provider('localStorageService', function() {
110
110
return false ;
111
111
}
112
112
} ( ) ) ;
113
-
113
+
114
114
115
115
116
116
// Directly adds a value to local storage
@@ -119,7 +119,7 @@ angularLocalStorage.provider('localStorageService', function() {
119
119
var addToLocalStorage = function ( key , value ) {
120
120
121
121
// If this browser does not support local storage use cookies
122
- if ( ! browserSupportsLocalStorage || this . storageType === 'cookie' ) {
122
+ if ( ! browserSupportsLocalStorage || self . storageType === 'cookie' ) {
123
123
$rootScope . $broadcast ( 'LocalStorageModule.notification.warning' , 'LOCAL_STORAGE_NOT_SUPPORTED' ) ;
124
124
if ( notify . setItem ) {
125
125
$rootScope . $broadcast ( 'LocalStorageModule.notification.setitem' , { key : key , newvalue : value , storageType : 'cookie' } ) ;
@@ -138,7 +138,7 @@ angularLocalStorage.provider('localStorageService', function() {
138
138
}
139
139
if ( webStorage ) { webStorage . setItem ( deriveQualifiedKey ( key ) , value ) } ;
140
140
if ( notify . setItem ) {
141
- $rootScope . $broadcast ( 'LocalStorageModule.notification.setitem' , { key : key , newvalue : value , storageType : this . storageType } ) ;
141
+ $rootScope . $broadcast ( 'LocalStorageModule.notification.setitem' , { key : key , newvalue : value , storageType : self . storageType } ) ;
142
142
}
143
143
} catch ( e ) {
144
144
$rootScope . $broadcast ( 'LocalStorageModule.notification.error' , e . message ) ;
@@ -151,7 +151,7 @@ angularLocalStorage.provider('localStorageService', function() {
151
151
// Example use: localStorageService.get('library'); // returns 'angular'
152
152
var getFromLocalStorage = function ( key ) {
153
153
154
- if ( ! browserSupportsLocalStorage || this . storageType === 'cookie' ) {
154
+ if ( ! browserSupportsLocalStorage || self . storageType === 'cookie' ) {
155
155
$rootScope . $broadcast ( 'LocalStorageModule.notification.warning' , 'LOCAL_STORAGE_NOT_SUPPORTED' ) ;
156
156
return getFromCookies ( key ) ;
157
157
}
@@ -184,7 +184,7 @@ angularLocalStorage.provider('localStorageService', function() {
184
184
try {
185
185
webStorage . removeItem ( deriveQualifiedKey ( key ) ) ;
186
186
if ( notify . removeItem ) {
187
- $rootScope . $broadcast ( 'LocalStorageModule.notification.removeitem' , { key : key , storageType : this . storageType } ) ;
187
+ $rootScope . $broadcast ( 'LocalStorageModule.notification.removeitem' , { key : key , storageType : self . storageType } ) ;
188
188
}
189
189
} catch ( e ) {
190
190
$rootScope . $broadcast ( 'LocalStorageModule.notification.error' , e . message ) ;
@@ -335,7 +335,7 @@ angularLocalStorage.provider('localStorageService', function() {
335
335
var cookies = $document . cookie . split ( ';' ) ;
336
336
for ( var i = 0 ; i < cookies . length ; i ++ ) {
337
337
thisCookie = cookies [ i ] ;
338
-
338
+
339
339
while ( thisCookie . charAt ( 0 ) === ' ' ) {
340
340
thisCookie = thisCookie . substring ( 1 , thisCookie . length ) ;
341
341
}
0 commit comments