Skip to content

Instantly share code, notes, and snippets.

@xdougx
Created June 27, 2013 18:41
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xdougx/5879172 to your computer and use it in GitHub Desktop.
Save xdougx/5879172 to your computer and use it in GitHub Desktop.
var IApp = (function() {
var InterfaceApp = function() {
this.run = function(obj, vars) {
if(obj == null) { obj = this.modules; }
if(vars !== undefined) { this.addGlobals(vars); }
this.callEvents(obj);
};
this.callEvents = function(obj){
for(var method in obj){
if(method.match(/call|run/) != null ) continue;
if(typeof obj[method] === "object") {
this.run(obj[method]);
} else if(typeof obj[method] === "function"){
obj[method]();
}
}
};
this.modules = {};
this.addModules = function(modules){
for(var module in modules) {
modules["globals"] = this.globals;
this.modules[module] = modules[module];
}
this.modules["globals"] = this.globals;
return this;
}
this.globals = {};
this.addGlobals = function(vars){
if(typeof vars == "object" ){
for(var e in vars) {
this.globals[e] = vars[e];
}
}
this.addGlobalsToModules(vars);
}
this.addGlobalsToModules = function(vars){
for(var module in this.modules){
if( this.modules[module]["globals"] === undefined ){
this.modules[module]["globals"] = {}
}
for(var e in vars) {
this.modules[module]["globals"][e] = vars[e];
}
}
}
}
//shared
InterfaceApp.prototype = {
_globals: function(){
return this.globals;
}
}
return InterfaceApp;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment