Last active
January 19, 2016 03:02
-
-
Save etoxin/9ef15954761a51b2300d to your computer and use it in GitHub Desktop.
Javascript Module Loader
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
// 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(); | |
} | |
} | |
}); |
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
/** | |
* 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