Skip to content

Instantly share code, notes, and snippets.

@ericorruption
Created January 28, 2016 19:27
Show Gist options
  • Save ericorruption/b5ea5cd847cc88a8889e to your computer and use it in GitHub Desktop.
Save ericorruption/b5ea5cd847cc88a8889e to your computer and use it in GitHub Desktop.
Garber-Irish DOM-Based module loading
var APP = {
common: {
init: function() {
// application-wide code
}
}
};
window.UTIL = {
exec: function( controller, action ) {
var ns = APP,
action = ( action === undefined ) ? 'init' : action;
if ( controller !== '' && ns[controller] && typeof ns[controller][action] == 'function' ) {
ns[controller][action]();
}
},
init: function() {
var body = document.body,
controller = body.getAttribute( 'data-controller' ),
action = body.getAttribute( 'data-action' );
UTIL.exec( 'common' );
UTIL.exec( controller );
UTIL.exec( controller, action );
}
};
window.UTIL.init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment