aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorValerio Virgillito2012-02-22 00:49:47 -0800
committerValerio Virgillito2012-02-22 00:49:47 -0800
commit8974ecd564563a991ff96f9cb6d47da172174242 (patch)
tree4518e1f28193000f737bd1297397f5a1f3a87b6e /js
parent2f24dafec79583547fe663d5a387d8ef15aae3bf (diff)
downloadninja-8974ecd564563a991ff96f9cb6d47da172174242.tar.gz
local storage integration and versioning
- Fixed the splitters Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'js')
-rwxr-xr-xjs/controllers/local-storage-controller.js51
-rwxr-xr-xjs/data/settings.js17
-rwxr-xr-xjs/ninja.reel/ninja.html13
-rwxr-xr-xjs/panels/Splitter.js22
4 files changed, 64 insertions, 39 deletions
diff --git a/js/controllers/local-storage-controller.js b/js/controllers/local-storage-controller.js
index 6963b245..ea763cff 100755
--- a/js/controllers/local-storage-controller.js
+++ b/js/controllers/local-storage-controller.js
@@ -7,7 +7,46 @@ 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
12 canStore: {
13 value: null
14 },
15
16 deserializedFromTemplate: {
17 value: function() {
18 this.canStore = window.localStorage;
19 this.application.localStorage = this;
20
21 // Redefine setItem and getItem if local storage is not available.
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 }
33 }
34 },
35
36 _getItem: {
37 value: function(key) {
38 var value = window.localStorage.getItem("ninja-" + key);
39 if(value !== null) value = JSON.parse(value);
40
41 return value;
42 }
43 },
44
45 _setItem: {
46 value: function(key, value) {
47 window.localStorage.setItem("ninja-" + key, JSON.stringify(value));
48 }
49 },
11 50
12 getItem: { 51 getItem: {
13 value: function(item) { 52 value: function(item) {
@@ -22,16 +61,6 @@ exports.LocalStorage = Montage.create( Montage, {
22 return null; 61 return null;
23 } 62 }
24 63
25 /*
26 if (window.localStorage) {
27 this.getItem = function(item) {
28 return window.localStorage.getItem(item);
29 }(item);
30 } else {
31 alert("Local Storage is not supported on your browser");
32
33 }
34 */
35 } 64 }
36 }, 65 },
37 66
diff --git a/js/data/settings.js b/js/data/settings.js
index ffea2075..6b1af3fc 100755
--- a/js/data/settings.js
+++ b/js/data/settings.js
@@ -10,10 +10,6 @@ var Montage = require("montage/core/core").Montage,
10 10
11exports.Settings = Montage.create( Component, { 11exports.Settings = Montage.create( Component, {
12 12
13 version: {
14 value: "11.1213"
15 },
16
17 _settings: { 13 _settings: {
18 value: null 14 value: null
19 }, 15 },
@@ -54,18 +50,5 @@ exports.Settings = Montage.create( Component, {
54 return null; 50 return null;
55 } 51 }
56 } 52 }
57 },
58
59 deserializedFromSerialization: {
60 value: function() {
61
62 if (LocalStorage.getItem("version") != this.version) {
63 this.settings = {}
64 LocalStorage.setItem("version",this.version);
65 } else {
66 this.settings = LocalStorage.getItem("settings");
67 }
68
69 }
70 } 53 }
71}); \ No newline at end of file 54}); \ No newline at end of file
diff --git a/js/ninja.reel/ninja.html b/js/ninja.reel/ninja.html
index 022b3f0a..43774d30 100755
--- a/js/ninja.reel/ninja.html
+++ b/js/ninja.reel/ninja.html
@@ -22,6 +22,11 @@
22 "name": "Preloader" 22 "name": "Preloader"
23 }, 23 },
24 24
25 "localStorage": {
26 "module": "js/controllers/local-storage-controller",
27 "name": "LocalStorage"
28 },
29
25 "settings1": { 30 "settings1": {
26 "module": "js/data/settings", 31 "module": "js/data/settings",
27 "name": "Settings" 32 "name": "Settings"
@@ -324,12 +329,12 @@
324 <nav id="mainMenuBar"></nav> 329 <nav id="mainMenuBar"></nav>
325 </section> 330 </section>
326 331
327 <section id="leftSplitter" class="leftSplitter splitter"></section> 332 <section data-montage-id="leftSplitter" class="leftSplitter splitter"></section>
328 333
329 <section id="rightSplitter" class="rightSplitter splitter"></section> 334 <section data-montage-id="rightSplitter" class="rightSplitter splitter"></section>
330 335
331 <section id="appContainer"> 336 <section id="appContainer">
332 <section id="topSplitter" class="topSplitter splitter"></section> 337 <section data-montage-id="topSplitter" class="topSplitter splitter"></section>
333 338
334 <section id="topPanelContainer" class="panelContainer"> 339 <section id="topPanelContainer" class="panelContainer">
335 <div id="topPanel" class="panel"> 340 <div id="topPanel" class="panel">
@@ -392,7 +397,7 @@
392 </section> 397 </section>
393 </section> 398 </section>
394 399
395 <section id="bottomSplitter" class="bottomSplitter splitter"></section> 400 <section data-montage-id="bottomSplitter" class="bottomSplitter splitter"></section>
396 </section> 401 </section>
397 402
398 <section id="popupWindows"></section> 403 <section id="popupWindows"></section>
diff --git a/js/panels/Splitter.js b/js/panels/Splitter.js
index 9f5b4de7..cb05104d 100755
--- a/js/panels/Splitter.js
+++ b/js/panels/Splitter.js
@@ -9,6 +9,10 @@ var Component = require("montage/ui/component").Component;
9 9
10exports.Splitter = Montage.create(Component, { 10exports.Splitter = Montage.create(Component, {
11 11
12 version: {
13 value: "1.0"
14 },
15
12 hasTemplate: { 16 hasTemplate: {
13 value: false 17 value: false
14 }, 18 },
@@ -49,19 +53,23 @@ exports.Splitter = Montage.create(Component, {
49 get: function() { 53 get: function() {
50 return this._collapsed; 54 return this._collapsed;
51 }, 55 },
52 set: function(value) 56 set: function(value) {
53 {
54 this._collapsed = value; 57 this._collapsed = value;
55 this.application.ninja.settings.setSetting(this.element.id, "collapsed", this.collapsed); 58
59 this.application.localStorage._setItem(this.element.getAttribute("data-montage-id"), {"version": this.version, "value": value});
56 } 60 }
57 }, 61 },
58 62
59 prepareForDraw: { 63 prepareForDraw: {
60 value: function() { 64 value: function() {
61 //Get Setting from SettingManager 65 //Get splitter initial value from SettingManager
62 this.application.ninja.settings.getSetting(this.element.id, "collapsed"); 66 var storedData = this.application.localStorage._getItem(this.element.getAttribute("data-montage-id"));
63 lapsed = false; 67 if(storedData && this.element.getAttribute("data-montage-id") !== null) {
64 if (lapsed != null) this._collapsed = lapsed; 68 this._collapsed = storedData.value;
69 } else {
70 this._collapsed = false;
71 }
72
65 this.element.addEventListener("click", this, false); 73 this.element.addEventListener("click", this, false);
66 } 74 }
67 }, 75 },