Skip to content

Instantly share code, notes, and snippets.

@marcoslhc
Created October 5, 2012 01:46
Show Gist options
  • Save marcoslhc/3837598 to your computer and use it in GitHub Desktop.
Save marcoslhc/3837598 to your computer and use it in GitHub Desktop.
garber-irish implementation
/*
Usage:
<script src="path/to/js/garber-irish-implementation.js">
<body data-controller="users" data-action="show">
*/
SITENAME = {
common: {
init: function() {
// application-wide code
}
},
users: {
init: function() {
// controller-wide code
},
show: function() {
// action-specific code
}
}
};
UTIL = {
exec: function( controller, action ) {
var ns = SITENAME,
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 );
}
};
$( document ).ready( UTIL.init );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment