X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=hacks%2FHack.js;h=2b0e5f7e05a78ee759e6b9c972bebfa7b5bf3da7;hb=5045171980085a8227a7fdd2a04724a2fd9830b2;hp=28cfad7821a9f05f088b41059134d3d9cfb2e5eb;hpb=7f476a519a8abeecf6c1e19e4e91635ea324d608;p=Hacks.git diff --git a/hacks/Hack.js b/hacks/Hack.js index 28cfad7..2b0e5f7 100644 --- a/hacks/Hack.js +++ b/hacks/Hack.js @@ -3,6 +3,17 @@ enyo.kind({ name: "Hack", kind: "VFlexBox", + preferences: [], + create: function() { + this.inherited(arguments); + try { + var str = localStorage['hacks/' + this.kind]; + if (str) + this.setPreferences(JSON.parse(str), true, true); + } catch(e) { + enyo.log("Could not load preferences: " + e.toString()); + } + }, stop: function() { }, start: function() { @@ -10,5 +21,35 @@ enyo.kind({ resize: function() { }, hidden: function() { - } + }, + getPreferencesMetadata: function() { + return this.preferences; + }, + getPreferences: function() { + var o = {}; + for (var i = 0; i < this.preferences.length; i++) { + var p = this.preferences[i]; + o[p.name] = this[p.name]; + } + return o; + }, + setPreferences: function(prefs, nosave, nonotify) { + for (var i in prefs) { + if (this[i] == undefined) + throw new Error('Cannot set nonexistent preference "' + i + '"'); + this[i] = prefs[i]; + } + if (!nosave) + this.savePreferences(); + if (!nonotify) + this.preferencesChanged(); + }, + savePreferences: function() { + try { + localStorage['hacks/' + this.kind] = JSON.stringify(this.getPreferences()); + } catch(e) { + enyo.log("Could not save prefs: " + e.toString()); + } + }, + preferencesChanged: function() { } });