aboutsummaryrefslogtreecommitdiff
path: root/js/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'js/controllers')
-rwxr-xr-xjs/controllers/local-storage-controller.js67
1 files changed, 37 insertions, 30 deletions
diff --git a/js/controllers/local-storage-controller.js b/js/controllers/local-storage-controller.js
index 6963b245..1388f3e5 100755
--- a/js/controllers/local-storage-controller.js
+++ b/js/controllers/local-storage-controller.js
@@ -7,44 +7,51 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
7var Montage = require("montage/core/core").Montage, 7var Montage = require("montage/core/core").Montage,
8 Component = require("montage/ui/component").Component; 8 Component = require("montage/ui/component").Component;
9 9
10exports.LocalStorage = Montage.create( Montage, { 10exports.LocalStorage = Montage.create( Component, {
11 11
12 getItem: { 12 canStore: {
13 value: function(item) { 13 value: null
14 var item; 14 },
15
16 if (window.localStorage) {
17 item = window.localStorage.getItem(item);
18 if(item !== null) return JSON.parse(item)
19 return null;
20 } else {
21 alert("Local Storage is not supported on your browser");
22 return null;
23 }
24 15
25 /* 16 deserializedFromTemplate: {
26 if (window.localStorage) { 17 value: function() {
27 this.getItem = function(item) { 18 this.canStore = window.localStorage;
28 return window.localStorage.getItem(item); 19 this.application.localStorage = this;
29 }(item); 20
30 } else { 21 // Redefine setItem and getItem if local storage is not available.
31 alert("Local Storage is not supported on your browser"); 22 if(!this.canStore) {
23 this.getItem = function() {
24 console.log("Local Storage is not supported on your browser");
25 return "";
26 };
27
28 this.setItem = function() {
29 console.log("Local Storage is not supported on your browser");
30 return false;
31 }
32 }
32 33
34 // Temporary clear the local storage if we find the version key
35 if(window.localStorage.version) {
36 window.localStorage.clear();
33 } 37 }
34 */ 38 }
39 },
40
41 getItem: {
42 value: function(key) {
43 var value = window.localStorage.getItem("ninja-" + key);
44 if(value !== null) value = JSON.parse(value);
45
46 return value;
35 } 47 }
36 }, 48 },
37 49
38 setItem: { 50 setItem: {
39 value: function(item, value) { 51 value: function(key, value) {
40 if (window.localStorage) { 52 window.localStorage.setItem("ninja-" + key, JSON.stringify(value));
41 window.localStorage.setItem(item, JSON.stringify(value)); 53
42 return true; 54 return value;
43 } else {
44 alert("Local Storage is not supported on your browser");
45 return false;
46 }
47 } 55 }
48 } 56 }
49
50}); \ No newline at end of file 57}); \ No newline at end of file