Skip to content

Instantly share code, notes, and snippets.

@lmartins
Created February 25, 2014 12:45
Show Gist options
  • Save lmartins/9208150 to your computer and use it in GitHub Desktop.
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
# 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