Giter VIP home page Giter VIP logo

Comments (13)

joshuajansen avatar joshuajansen commented on June 27, 2024

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>

from magnific-popup-rails.

asok avatar asok commented on June 27, 2024

@joshuajansen thanks. Indeed it seems like using data-no-turbolink is the only solution. It is definitely worth mentioning that in the README.

It looks that turbolinks are not specific to rails only now. Maybe it's worth opening such issue in the mainstream?

from magnific-popup-rails.

veriel avatar veriel commented on June 27, 2024

I've tried:
1: Using

$(document).on('page:load ready', function()

instead of

$(document).ready()

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.

from magnific-popup-rails.

andrewnguyen42 avatar andrewnguyen42 commented on June 27, 2024

+1 to this one, I just spent 6+ hours trying to track this one down

from magnific-popup-rails.

glebtv avatar glebtv commented on June 27, 2024

Here's how it works for me:
Comment the condition if (!_body)
https://github.com/joshuajansen/magnific-popup-rails/blob/master/vendor/assets/javascripts/magnific-popup/jquery.magnific-popup.js#L148-L150
here. So it always gets current document.body.

from magnific-popup-rails.

jeremyrajan avatar jeremyrajan commented on June 27, 2024

Thanks @glebtv ! Commenting the condition did the trick 👍

from magnific-popup-rails.

tirdadc avatar tirdadc commented on June 27, 2024

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?

from magnific-popup-rails.

mitchellfyi avatar mitchellfyi commented on June 27, 2024

Looks like it's opening everything under the original document.body element. So change the line to:

_body = $("body");

from magnific-popup-rails.

lassebunk avatar lassebunk commented on June 27, 2024

+1 to your solution with always loading

_body = $("body");

I guess this would be a problem with other JavaScript frameworks that replace the body.

from magnific-popup-rails.

itsNikolay avatar itsNikolay commented on June 27, 2024

@glebtv great thanks
@joshuajansen please update the gem on rubygems

now I've fixed it with the fork of the repo
and replaced a line with the gem by:
gem 'magnific-popup-rails', github: 'itsNikolay/magnific-popup-rails'
now it works well
with it will help other developers

from magnific-popup-rails.

joshuajansen avatar joshuajansen commented on June 27, 2024

@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! :shipit:

from magnific-popup-rails.

mtomov avatar mtomov commented on June 27, 2024

Thank you guys for the suggested solution! It works.

from magnific-popup-rails.

glebtv avatar glebtv commented on June 27, 2024

Update,
currently this:

$(document).on('page:change', ->
  $.magnificPopup.close()
)

is also required or pop up won't open if turbolinks navigation was triggered when pop ups were open, or it stops working.

from magnific-popup-rails.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.