Created
February 25, 2014 12:45
-
-
Save lmartins/9208150 to your computer and use it in GitHub Desktop.
Load application javascript code based on the current view/controller
http://viget.com/inspire/extending-paul-irishs-comprehensive-dom-ready-execution
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
# http://viget.com/inspire/extending-paul-irishs-comprehensive-dom-ready-execution | |
SITENAME = | |
common: | |
init: -> | |
# application-wide code | |
users: | |
init: -> | |
# controller-wide code | |
show: -> | |
# action-specific code | |
UTIL = | |
exec: (controller, action) -> | |
ns = SITENAME | |
action = (if (action is `undefined`) then "init" else action) | |
ns[controller][action]() if controller isnt "" and ns[controller] and typeof ns[controller][action] is "function" | |
init: -> | |
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