Created
October 5, 2012 01:46
-
-
Save marcoslhc/3837598 to your computer and use it in GitHub Desktop.
garber-irish implementation
This file contains 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
/* | |
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