-
Notifications
You must be signed in to change notification settings - Fork 18
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
Integration with turbolinks #4
Comments
You could try something like this to check if Magnific popup is already initialized: $(".photo-gallery").data("magnificPopup") is `undefined`
# initialize magnific popup But I think there may be another problem, because even without binding a second time it still doesn't work properly. I've added some callbacks ( http://dimsemenov.com/plugins/magnific-popup/documentation.html#api ) and even though all these callbacks are triggered just like they do on the first request, the popup just won't show. For now I'm just opting out of turbolinks for the page that uses magnific popup by adding data-no-turbolink to the parent container. <li data-no-turbolink><%= link_to "Home", root_url %></li> |
@joshuajansen thanks. Indeed it seems like using It looks that turbolinks are not specific to rails only now. Maybe it's worth opening such issue in the mainstream? |
I've tried:
instead of
2: Checking for double binding. 3: Adding jquery.turboolinks to the application.js None of these helped. The only solution for now is to turn off turbolinks on those links that lead to Magnific Popup pages. It can turn into a maintenance nightmare over time. I can't even write automated tests for this. |
+1 to this one, I just spent 6+ hours trying to track this one down |
Here's how it works for me: |
Thanks @glebtv ! Commenting the condition did the trick 👍 |
That link doesn't show any condition on (!_body) but _body = $(document.body); so I assumed it's been changed. Has anyone managed to get this to work with the newer code? |
Looks like it's opening everything under the original document.body element. So change the line to:
|
+1 to your solution with always loading _body = $("body"); I guess this would be a problem with other JavaScript frameworks that replace the body. |
@glebtv great thanks now I've fixed it with the fork of the repo |
@itsNikolay this fix actually belongs in the core (https://github.com/dimsemenov/Magnific-Popup), but it seems that they're not too eager with merging the open pull requests. So feel free to create a pull to this repo, I'll merge it in right away! |
Thank you guys for the suggested solution! It works. |
Update,
is also required or pop up won't open if turbolinks navigation was triggered when pop ups were open, or it stops working. |
Hey, as far I've tried it does not well with turbolinks. I have such peace of code:
When I start in a page with element
$('.photo-gallery')
I click on it and magnific show the gallery. Then I go to some other page using turbolinks. When I go back to the first page after clicking on the element nothing happens.It seems like it was already initialized for this element (that at this time is in the turbolinks cache (?)). And magnific stops working if initialized for the second time on the same element. Is there a way to check if magnific was already initialized for a giving element?
The text was updated successfully, but these errors were encountered: