lmartins
2/25/2014 - 12:45 PM

Load application javascript code based on the current view/controller http://viget.com/inspire/extending-paul-irishs-comprehensive-dom-ready

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