X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=Main.js;h=8f9789efe80bad6cb9c7bdea40fad0d3357104d2;hb=be221ae155290b04705bd1a6deeb82f495def012;hp=c8a2c19995080912026a18043ff32bd0c47e5fd7;hpb=5045171980085a8227a7fdd2a04724a2fd9830b2;p=Hacks.git diff --git a/Main.js b/Main.js index c8a2c19..8f9789e 100644 --- a/Main.js +++ b/Main.js @@ -32,12 +32,14 @@ enyo.kind({ ], create: function() { this.inherited(arguments); - /* - this.index = localStorage.getItem('hack.index'); - if (!this.index) + try { + this.index = localStorage.getItem('hack.index'); + if (!this.index) + this.index = 0; + } catch(e) { + enyo.log("Could not load last hack index"); this.index = 0; - */ - this.index = 0; + } this.lastScrollPos = 0; this.$.hacksCarousel.setCenterView(this.getHack(this.index)); }, @@ -83,11 +85,17 @@ enyo.kind({ } }, savePreferences: function(inSender, prefs) { - enyo.log("Saving prefs: " + JSON.stringify(prefs)); - this.back(); var view = this.$.hacksCarousel.fetchView('center'); - view.setPreferences(prefs); - view.start(); + if (prefs == null) { + enyo.log("Clearing prefs"); + view.resetPreferences(prefs); + this.selectHack(this, this.index); + } else { + enyo.log("Saving prefs: " + JSON.stringify(prefs)); + view.setPreferences(prefs); + view.start(); + } + this.back(); }, windowActivated: function() { this.startHack(); @@ -95,7 +103,7 @@ enyo.kind({ windowDeactivated: function() { this.stopHack(); }, - selectHack: function(inSender, inValue, inOldValue) { + selectHack: function(inSender, inValue) { this.stopHack(); this.index = inValue; this.lastScrollPos = 0; @@ -111,7 +119,11 @@ enyo.kind({ //enyo.log('starting view ' + view); if (view) view.start(); - //localStorage.setItem('hack.index', this.index); + try { + localStorage.setItem('hack.index', this.index); + } catch(e) { + enyo.log("Could not set hack index"); + } }, stopHack: function(direction) { var view = this.$.hacksCarousel.fetchView(direction || 'center');