/hacks/Hack.js
/* Copyright 2011 The Dominion of Awesome
* See COPYING for licensing information */
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() {
},
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());
}
},
resetPreferences: function() {
delete localStorage['hacks/' + this.kind];
},
preferencesChanged: function() { }
});