Skip to content

Commit 92323fa

Browse files
committed
Return storage type, code formatting, and uglification
1 parent 082df22 commit 92323fa

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

angular-local-storage.js

+17-11
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
'use strict';
44
var 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,

angular-local-storage.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/demo-app.js

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
angular.module('demoModule', ['LocalStorageModule'])
22
.config(['localStorageServiceProvider', function(localStorageServiceProvider){
33
localStorageServiceProvider.setPrefix('demoPrefix');
4+
// localStorageServiceProvider.setStorageCookieDomain('example.com');
5+
// localStorageServiceProvider.setStorageType('sessionStorage');
46
}])
57
.controller('DemoCtrl', [
68
'$scope',
@@ -16,6 +18,10 @@ angular.module('demoModule', ['LocalStorageModule'])
1618

1719
$scope.storageType = 'Local storage';
1820

21+
if (localStorageService.getStorageType().indexOf('session') >= 0) {
22+
$scope.storageType = 'Session storage'
23+
}
24+
1925
if (!localStorageService.isSupported) {
2026
$scope.storageType = 'Cookie';
2127
}

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
"grunt-cli": "~0.1.9"
2626
},
2727
"devDependencies": {
28-
"time-grunt": "~0.1.1",
29-
"load-grunt-tasks": "~0.1.0",
30-
"grunt-contrib-jshint": "~0.6.4",
28+
"time-grunt": "~0.2.9",
29+
"load-grunt-tasks": "~0.3.0",
30+
"grunt-contrib-jshint": "~0.8.0",
3131
"grunt": "~0.4.2",
32-
"grunt-contrib-uglify": "~0.2.7"
32+
"grunt-contrib-uglify": "~0.3.2"
3333
}
3434
}

0 commit comments

Comments
 (0)