Created
May 14, 2015 17:35
-
-
Save mnazim/bc42a5a18e8916d5b149 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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