turbolinks / turbolinks-classic

Classic version of Turbolinks. Now deprecated in favor of Turbolinks 5.
MIT License
3.54k stars 431 forks source link

JS isn't firing after the user hits the back button #533

Closed gregblass closed 9 years ago

gregblass commented 9 years ago

After the user hits the back button, none of my JS is firing...all my bootstrap stuff, and also my mobile fly-out menu:

$(function() {
  $("#menu-trigger").click(function() {
    $("body").toggleClass("nav-open");
   });
 });

I have jquery.turbolinks set up correctly as far as I know.

Has anyone else experienced this?

gregblass commented 9 years ago

Looks like someone has asked this already: https://github.com/rails/turbolinks/issues/507

And commited a solution here: https://github.com/rails/turbolinks/pull/509

What if there is no script tag though? My code is in application.js. And what about all the baked in bootstrap code? Popovers, Tooltips, Modals, etc...

gregblass commented 9 years ago

My solution was to just place your code in a script tag with data-turbolinks-eval=always on the bottom of your application.html.erb, and remove the jQuery onready. Then any js in there is fired even when using back or forward.