module.js | |
---|---|
Mod.Module | |
Modules are responsible for defining the specific behavior of pieces of your application. All the functionality of your application will be defined in modules. | Mod.Module = (function() { |
Each module contains a | function Module(name) {
if (is_undefined(name)) {
throw new Error("Mod.Module(name): name is undefined");
}
this.dom = new Mod.DOM;
this.data = {};
this.name = name;
} |
actionsThe actions method is a placholder to be overwritten in each instance | Module.prototype.actions = function() {}; |
runWait for the DOM to be ready and execute the actions | Module.prototype.run = function() {
var mod = this;
this.dom.call_when_ready(function() {
mod.execute();
});
}; |
executeExecute the actions immediately | Module.prototype.execute = function() {
this.actions();
}; |
elementsServes as an api to set and get elements from the module's | Module.prototype.elements = function(elements) {
if (is_undefined(elements)) {
return this.dom.cache;
} |
Look up cached element by string key | if (is_string(elements)) {
var name = elements;
return this.dom.cache[name];
} |
cache the DOM objects | else {
this.dom.add_elements(elements);
}
}; |
set_dataConvenience method to add properties to the | Module.prototype.set_data = function(key, value) {
if (is_undefined(key)) {
throw new Error(this.name + '.set_data(key, value): key is undefined');
}
if (is_typeof(String, key) && is_undefined(value)) {
throw new SyntaxError(this.name + 'Module.set_data(key, value): value is undefined');
}
if (is_typeof(String, key)) {
this.data[key] = value;
}
else if (is_typeof(Object, key)) {
var data = key;
for(var property in data) {
this.data[property] = data[property];
}
}
return this;
};
return Module;
})();
|