Add global color list
[Hacks.git] / hacks / Hack.js
index 2133299..13e1912 100644 (file)
@@ -4,6 +4,16 @@ 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() {
@@ -23,14 +33,26 @@ enyo.kind({
                }
                return o;
        },
-       setPreferences: function(prefs) {
+       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];
                }
-               this.preferencesChanged();
+               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());
+               }
+       },
+       resetPreferences: function() {
+               delete localStorage['hacks/' + this.kind];
        },
-       preferencesChanged: function() {
-       }
+       preferencesChanged: function() { }
 });