Skip to content

Instantly share code, notes, and snippets.

@mnazim
Created May 14, 2015 17:35
Show Gist options
  • Save mnazim/bc42a5a18e8916d5b149 to your computer and use it in GitHub Desktop.
Save mnazim/bc42a5a18e8916d5b149 to your computer and use it in GitHub Desktop.
(function () {
var Modular = function () {
this.VERSION = '0.0.1',
this.modules = {},
this.activeModules = [],
this.currentPath = undefined,
this.registeredPaths = undefined,
this.host = undefined,
this.protocol = undefined;
};
Modular.prototype.log = function (message) {
console.log(message);
}
Modular.prototype.register = function (module) {
var mod = {};
mod[module.name] = module;
_.extend(this.modules, mod);
};
Modular.prototype.init = function () {
this.currentPath = window.location.pathname;
this.host = window.location.hostname;
this.protocol = window.location.protocol;
this.postInit();
};
Modular.prototype.postInit = function () {
for (var name in this.modules) {
module = this.modules[name];
for (var i = 0; i < module.paths.length; i++) {
if (this.currentPath.match(new RegExp(module.paths[i]))) {
var mod = {};
mod[name] = module.activate();
_.extend(this.activeModules, mod);
break;
}
}
}
};
window._Modular = new Modular();
$(function () {
window._Modular.init();
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment