From 8974ecd564563a991ff96f9cb6d47da172174242 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 22 Feb 2012 00:49:47 -0800 Subject: local storage integration and versioning - Fixed the splitters Signed-off-by: Valerio Virgillito --- js/controllers/local-storage-controller.js | 51 +++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 11 deletions(-) (limited to 'js/controllers/local-storage-controller.js') 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 var Montage = require("montage/core/core").Montage, Component = require("montage/ui/component").Component; -exports.LocalStorage = Montage.create( Montage, { +exports.LocalStorage = Montage.create( Component, { + + canStore: { + value: null + }, + + deserializedFromTemplate: { + value: function() { + this.canStore = window.localStorage; + this.application.localStorage = this; + + // Redefine setItem and getItem if local storage is not available. + if(!this.canStore) { + this._getItem = function() { + console.log("Local Storage is not supported on your browser"); + return ""; + }; + + this._setItem = function() { + console.log("Local Storage is not supported on your browser"); + return false; + } + } + } + }, + + _getItem: { + value: function(key) { + var value = window.localStorage.getItem("ninja-" + key); + if(value !== null) value = JSON.parse(value); + + return value; + } + }, + + _setItem: { + value: function(key, value) { + window.localStorage.setItem("ninja-" + key, JSON.stringify(value)); + } + }, getItem: { value: function(item) { @@ -22,16 +61,6 @@ exports.LocalStorage = Montage.create( Montage, { return null; } - /* - if (window.localStorage) { - this.getItem = function(item) { - return window.localStorage.getItem(item); - }(item); - } else { - alert("Local Storage is not supported on your browser"); - - } - */ } }, -- cgit v1.2.3 From f97080989ee988c1e613915c2d246dc17b104b3b Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Fri, 24 Feb 2012 13:27:33 -0800 Subject: clearing the old local setting and using the new version/prefix local settings. Signed-off-by: Valerio Virgillito --- js/controllers/local-storage-controller.js | 42 +++++++----------------------- 1 file changed, 10 insertions(+), 32 deletions(-) (limited to 'js/controllers/local-storage-controller.js') diff --git a/js/controllers/local-storage-controller.js b/js/controllers/local-storage-controller.js index ea763cff..1388f3e5 100755 --- a/js/controllers/local-storage-controller.js +++ b/js/controllers/local-storage-controller.js @@ -20,20 +20,25 @@ exports.LocalStorage = Montage.create( Component, { // Redefine setItem and getItem if local storage is not available. if(!this.canStore) { - this._getItem = function() { + this.getItem = function() { console.log("Local Storage is not supported on your browser"); return ""; }; - this._setItem = function() { + this.setItem = function() { console.log("Local Storage is not supported on your browser"); return false; } } + + // Temporary clear the local storage if we find the version key + if(window.localStorage.version) { + window.localStorage.clear(); + } } }, - _getItem: { + getItem: { value: function(key) { var value = window.localStorage.getItem("ninja-" + key); if(value !== null) value = JSON.parse(value); @@ -42,38 +47,11 @@ exports.LocalStorage = Montage.create( Component, { } }, - _setItem: { + setItem: { value: function(key, value) { window.localStorage.setItem("ninja-" + key, JSON.stringify(value)); - } - }, - - getItem: { - value: function(item) { - var item; - if (window.localStorage) { - item = window.localStorage.getItem(item); - if(item !== null) return JSON.parse(item) - return null; - } else { - alert("Local Storage is not supported on your browser"); - return null; - } - - } - }, - - setItem: { - value: function(item, value) { - if (window.localStorage) { - window.localStorage.setItem(item, JSON.stringify(value)); - return true; - } else { - alert("Local Storage is not supported on your browser"); - return false; - } + return value; } } - }); \ No newline at end of file -- cgit v1.2.3