Skip to content

Commit ccb0d8a

Browse files
author
Kevin Pheasey
committed
Remove Turbolinks dependency in initializer and add support for all versions of Turbolinks.
1 parent d8c9689 commit ccb0d8a

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

lib/rails_script/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module RailsScript
2-
VERSION = '2.0.0'
2+
VERSION = '2.0.1'
33
end

vendor/assets/javascripts/rails_script/init.coffee

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ window.App ||= {}
33
window.Element ||= {}
44
window.Utility ||= {}
55

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

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

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

21+
# Clear event handlers on navigation
1922
RailsScript.setClearEventHandlers = ->
20-
jQuery(document).on 'turbolinks:before-visit', ->
23+
jQuery(document).on 'page:before-change turbolinks:before-visit', ->
2124
for element in [window, document]
2225
for event, handlers of (jQuery._data(element, 'events') || {})
2326
for handler in handlers

0 commit comments

Comments
 (0)