forked from GUMGA/components
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWebStorage.js
executable file
·61 lines (59 loc) · 1.42 KB
/
WebStorage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
(function(){
'use strict';
WebStorage.$inject = [];
function WebStorage(){
return {
setSessionStorageItem: function(key,value){
var _value = value;
if(typeof value == 'object'){
_value = angular.toJson(value);
}
window.sessionStorage.setItem(key,_value);
},
getSessionStorageItem: function(key){
var g = window.sessionStorage.getItem(key);
if(!g){
return null;
}
try {
angular.fromJson(g);
}catch(e){
return g;
}
return angular.fromJson(g);
},
removeSessionStorageItem: function(key){
window.sessionStorage.removeItem(key);
},
clearSessionStorage: function(){
window.sessionStorage.clear();
},
getNumberOfItemsInSessionStorage: function(){
return window.sessionStorage.length;
},
setLocalStorageItem: function(key,value){
window.localStorage.setItem(key,angular.toJson(value));
},
getLocalStorageItem: function(key){
var g = window.localStorage.getItem(key);
try {
angular.fromJson(g);
}catch(e){
return g;
}
return angular.fromJson(g);
},
removeLocalStorageItem: function(key){
window.localStorage.removeItem(key);
},
clearLocalStorage: function(){
window.localStorage.clear();
},
getNumberOfItemsInLocalStorage: function(){
return window.localStorage.length;
}
}
}
angular.module('gumga.services.webstorage',[])
.factory('GumgaWebStorage',WebStorage)
})();