Sha256: afda84f121c026c6679bb4ce57a8cf6a8312b6bd9402c257e63fed77a7aef5a8

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

window.Initjs =
  initialize: ->
    infos = $("#init-js")
    controllerClass = infos.data("controller-class")
    controllerName = infos.data("controller-name")
    action = infos.data("action")
    this.execFilter('init')
    this.exec(controllerClass, controllerName, action)
    this.execFilter('finish')

  exec: (controllerClass, controllerName, action) ->
    namespace = App

    if controllerClass
      railsNamespace = controllerClass.split("::").slice(0, -1)
    else
      railsNamespace = []

    for name in railsNamespace
      namespace = namespace[name] if namespace

    if namespace and controllerName
      controller = namespace[controllerName]
      if controller and View = controller[action]
        App.currentView = window.view = new View()

  execFilter: (filterName) ->
    if App.Common and typeof App.Common[filterName] == 'function'
      App.Common[filterName]()

jQuery ->
  window.Initjs.execFilter('initPage') # If you are using the Turbolinks and you need run a code only one time.
  window.Initjs.initialize()

  unless window.Turbolinks is undefined
    $(document).bind "page:change", ->
      window.Initjs.initialize()

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
initjs-0.1.3 lib/assets/javascript/init.js.coffee
initjs-0.1.2 lib/assets/javascript/init.js.coffee