33'use strict' ;
44var angularLocalStorage = angular . module ( 'LocalStorageModule' , [ ] ) ;
55
6- angularLocalStorage . provider ( 'localStorageService' , function ( ) {
6+ angularLocalStorage . provider ( 'localStorageService' , function ( ) {
7+
78 // You should set a prefix to avoid overwriting any local storage variables from the rest of your app
89 // e.g. localStorageServiceProvider.setPrefix('youAppName');
910 // With provider you can use config as this:
1011 // myApp.config(function (localStorageServiceProvider) {
1112 // localStorageServiceProvider.prefix = 'yourAppName';
1213 // });
13-
1414 this . prefix = 'ls' ;
1515
1616 // You could change web storage type localstorage or sessionStorage
17- this . storageType = 'localStorage' ;
17+ this . storageType = 'localStorage' ;
1818
1919 // Cookie options (usually in case of fallback)
2020 // expiry = Number of days before cookies expire // 0 = Does not expire
@@ -31,38 +31,38 @@ angularLocalStorage.provider('localStorageService', function(){
3131 } ;
3232
3333 // Setter for the prefix
34- this . setPrefix = function ( prefix ) {
34+ this . setPrefix = function ( prefix ) {
3535 this . prefix = prefix ;
3636 } ;
3737
3838 // Setter for the storageType
39- this . setStorageType = function ( storageType ) {
39+ this . setStorageType = function ( storageType ) {
4040 this . storageType = storageType ;
4141 } ;
4242
4343 // Setter for cookie config
44- this . setStorageCookie = function ( exp , path ) {
44+ this . setStorageCookie = function ( exp , path ) {
4545 this . cookie = {
4646 expiry : exp ,
4747 path : path
4848 } ;
4949 } ;
5050
5151 // Setter for cookie domain
52- this . setStorageCookieDomain = function ( domain ) {
52+ this . setStorageCookieDomain = function ( domain ) {
5353 this . cookie . domain = domain ;
5454 } ;
5555
5656 // Setter for notification config
5757 // itemSet & itemRemove should be booleans
58- this . setNotify = function ( itemSet , itemRemove ) {
58+ this . setNotify = function ( itemSet , itemRemove ) {
5959 this . notify = {
6060 setItem : itemSet ,
6161 removeItem : itemRemove
6262 } ;
6363 } ;
6464
65- this . $get = [ '$rootScope' , '$window' , '$document' , function ( $rootScope , $window , $document ) {
65+ this . $get = [ '$rootScope' , '$window' , '$document' , function ( $rootScope , $window , $document ) {
6666
6767 var prefix = this . prefix ;
6868 var cookie = this . cookie ;
@@ -93,6 +93,7 @@ angularLocalStorage.provider('localStorageService', function(){
9393
9494 return true ;
9595 } catch ( e ) {
96+ storageType = 'cookie' ;
9697 $rootScope . $broadcast ( 'LocalStorageModule.notification.error' , e . message ) ;
9798 return false ;
9899 }
@@ -298,9 +299,9 @@ angularLocalStorage.provider('localStorageService', function(){
298299 }
299300
300301 var cookies = $document . cookie && $document . cookie . split ( ';' ) || [ ] ;
301- for ( var i = 0 ; i < cookies . length ; i ++ ) {
302+ for ( var i = 0 ; i < cookies . length ; i ++ ) {
302303 var thisCookie = cookies [ i ] ;
303- while ( thisCookie . charAt ( 0 ) === ' ' ) {
304+ while ( thisCookie . charAt ( 0 ) === ' ' ) {
304305 thisCookie = thisCookie . substring ( 1 , thisCookie . length ) ;
305306 }
306307 if ( thisCookie . indexOf ( prefix + key + '=' ) === 0 ) {
@@ -330,8 +331,13 @@ angularLocalStorage.provider('localStorageService', function(){
330331 }
331332 } ;
332333
334+ var getStorageType = function ( ) {
335+ return storageType ;
336+ } ;
337+
333338 return {
334339 isSupported : browserSupportsLocalStorage ,
340+ getStorageType : getStorageType ,
335341 set : addToLocalStorage ,
336342 add : addToLocalStorage , //DEPRECATED
337343 get : getFromLocalStorage ,
0 commit comments