Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 5 Turbolinks JQuery workaround? #121

Open
austinwalter opened this issue Dec 19, 2016 · 1 comment
Open

Rails 5 Turbolinks JQuery workaround? #121

austinwalter opened this issue Dec 19, 2016 · 1 comment

Comments

@austinwalter
Copy link

So before Rails 5 came out using metisMenu and Turbolinks wasn't a problem because the jquery.turbolinks gem fixed the discrepancies. But with Rails 5 that doesn't seem work anymore.

I was wondering if anyone knows of a work around?

@rocwrxsti
Copy link

@austinwalter I was having the same issue you are describing. After some searching around, I saw the same strategy a few times. Per the turbolinks github readme, attaching event listeners to window.onload, DOMContentLoaded, or jQuery ready doesn't work with turbolinks because those events don't fire except for on page load and reload. Instead, turbolinks has it's own "DOM ready" event that fires after content is loaded, namely turbolinks:load. Here is the link to the section in the readme.

The suggestion I kept seeing (and is also in the turbolinks readme) is to use the following for javascript:

document.addEventListener("turbolinks:load", function() {
  // ...
})

For jQuery I used (and what is working for me in my project):

$(document).on('turbolinks:load', function() {
  // ...
});

Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants