Created
January 28, 2016 19:27
-
-
Save ericorruption/b5ea5cd847cc88a8889e to your computer and use it in GitHub Desktop.
Garber-Irish DOM-Based module loading
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
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