Add gray to global colors list
[Hacks.git] / hacks / Hack.js
1 /* Copyright 2011 The Dominion of Awesome
2  * See COPYING for licensing information */
3 enyo.kind({
4         name: "Hack",
5         kind: "VFlexBox",
6         preferences: [],
7         create: function() {
8                 this.inherited(arguments);
9                 try {
10                         var str = localStorage['hacks/' + this.kind];
11                         if (str)
12                                 this.setPreferences(JSON.parse(str), true, true);
13                 } catch(e) {
14                         enyo.log("Could not load preferences: " + e.toString());
15                 }
16         },
17         stop: function() {
18         },
19         start: function() {
20         },
21         resize: function() {
22         },
23         hidden: function() {
24         },
25         getPreferencesMetadata: function() {
26                 return this.preferences;
27         },
28         getPreferences: function() {
29                 var o = {};
30                 for (var i = 0; i < this.preferences.length; i++) {
31                         var p = this.preferences[i];
32                         o[p.name] = this[p.name];
33                 }
34                 return o;
35         },
36         setPreferences: function(prefs, nosave, nonotify) {
37                 for (var i in prefs) {
38                         if (this[i] == undefined)
39                                 throw new Error('Cannot set nonexistent preference "' + i + '"');
40                         this[i] = prefs[i];
41                 }
42                 if (!nosave)
43                         this.savePreferences();
44                 if (!nonotify)
45                         this.preferencesChanged();
46         },
47         savePreferences: function() {
48                 try {
49                         localStorage['hacks/' + this.kind] = JSON.stringify(this.getPreferences());
50                 } catch(e) {
51                         enyo.log("Could not save prefs: " + e.toString());
52                 }
53         },
54         resetPreferences: function() {
55                 delete localStorage['hacks/' + this.kind];
56         },
57         preferencesChanged: function() { }
58 });