Skip to content

Commit

Permalink
Remove Turbolinks dependency in initializer and add support for all v…
Browse files Browse the repository at this point in the history
…ersions of Turbolinks.
  • Loading branch information
Kevin Pheasey committed May 26, 2016
1 parent d8c9689 commit ccb0d8a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/rails_script/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RailsScript
VERSION = '2.0.0'
VERSION = '2.0.1'
end
11 changes: 7 additions & 4 deletions vendor/assets/javascripts/rails_script/init.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ window.App ||= {}
window.Element ||= {}
window.Utility ||= {}

$(document).on "turbolinks:load.rails_script", ->
# Initializer
$(document).on "ready.rails_script page:load.rails_script turbolinks:load.rails_script", ->
controller = $('#rails-script').data('controller')
action = $('#rails-script').data('action')
Utility.RailsVars = $('#rails-script').data('vars')
window.$this = new (App["#{$('#rails-script').data('controller')}"] || App.Base)()

action = $('#rails-script').data('action')
window.$this = new (App[controller] || App.Base)()

if typeof $this.beforeAction == 'function'
$this.beforeAction action
Expand All @@ -16,8 +18,9 @@ $(document).on "turbolinks:load.rails_script", ->
if typeof $this.afterAction == 'function'
$this.afterAction action

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

0 comments on commit ccb0d8a

Please sign in to comment.