Skip to content

Instantly share code, notes, and snippets.

@etoxin
Last active January 19, 2016 03:02
Show Gist options
  • Save etoxin/9ef15954761a51b2300d to your computer and use it in GitHub Desktop.
Save etoxin/9ef15954761a51b2300d to your computer and use it in GitHub Desktop.
Javascript Module Loader
// All modules must have a init function.
/**
* ready Function
* @param fn
*/
function ready(fn) {
if (document.readyState != 'loading'){
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
ready(function(){
/**
* Module Initiator
* Make sure the module has a `init()` function. If so > initiate.
*/
for (var module in myApp) {
if('init' in myApp[module]){
myApp[module].init();
}
}
});
/**
* myApp.lazyImageLoader
*/
(function(window, myApp, undefined) {
function initiateLazyImageLoader() {
//TODO: This function will be used to lazy load the images where required.
}
// Public methods when this object is instantiated
// Expose `init` to module loader.
myApp.lazyImageLoader = {};
myApp.lazyImageLoader.init = initiateLazyImageLoader;
})(window, window.myApp = window.myApp || {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment