Skip to content

Instantly share code, notes, and snippets.

@jgarber623
Created July 19, 2010 03:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgarber623/480983 to your computer and use it in GitHub Desktop.
Save jgarber623/480983 to your computer and use it in GitHub Desktop.
A sample JavaScript structure for larger web applications
/*
* Based on Paul Irish's "Markup-based unobtrusive comprehensive DOM-ready execution"
* http://paulirish.com/2009/markup-based-unobtrusive-comprehensive-dom-ready-execution/
*/
SITE_NAMESPACE = {
common: {
init: function() {
}
}
};
UTIL = {
exec: function( controller, action ) {
var ns = SITE_NAMESPACE, action = ( action === undefined ) ? "init" : action;
if ( controller !== "" && ns[controller] && typeof( ns[controller][action] ) == "function" ) {
ns[controller][action]();
}
},
init: function() {
UTIL.exec( "common" );
UTIL.exec( document.body.getAttribute( "data-controller" ), document.body.getAttribute( "data-action" ) );
}
};
$().ready( UTIL.init );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment