Sha256: 7b3db63990231b65aac3c131b6db01f613c634181febc3f0d2ec8ab6c82a83f6

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 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')
    this.appName()

  appName: ->
    appName = $("#init-js").data('app-name') || "App"
    window.App = window[appName]
    if window.App is undefined
      console.log "Initjs: #{appName} is not defined. Run `rails generate initjs` to generate the app file."

  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) ->
    this.appName()
    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 to run a code only once.
  window.Initjs.initialize()

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

Version data entries

1 entries across 1 versions & 1 rubygems

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