Sha256: 178e80a3bc9b753ce5abceb20d55c58c6a63b2b3a734f44bb07170656b33a599

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

window.RailsScript ||= {}
window.App ||= {}
window.Element ||= {}
window.Utility ||= {}

if Turbolinks?
  $(document).on "page:load.rails_script turbolinks:load.rails_script", ->
    RailsScript.init()
else
  $(document).on "ready.rails_script", ->
    RailsScript.init()

# Initializer
RailsScript.init = ->
  controller = $('#rails-script').data('controller')
  action = $('#rails-script').data('action')
  Utility.RailsVars = $('#rails-script').data('vars')

  window.$this = new (App[controller] || App.Base)()

  if typeof $this.beforeAction == 'function'
    $this.beforeAction action
  if typeof $this[action] == 'function'
    $this[action]()
  if typeof $this.afterAction == 'function'
    $this.afterAction action

# Clear event handlers on navigation
RailsScript.setClearEventHandlers = ->
  jQuery(document).on 'page:before-change turbolinks:before-render', ->
    for element in [window, document]
      for event, handlers of (jQuery._data(element, 'events') || {})
        for handler in handlers
          if handler? && handler.namespace == ''
            jQuery(element).off event, handler.handler

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails_script-2.0.4 vendor/assets/javascripts/rails_script/init.coffee
rails_script-2.0.3 vendor/assets/javascripts/rails_script/init.coffee