I fixed two JavaScript bugs in the Drupal 8 version of this module. It may be that the same also exist in the Drupal 7 version, which should be checked eventually.

The patch attached fixes:

  • Double initialization an AJAX events which leads to non closing photoswipe layer when a page containing a photoswipe gallery is loaded via AJAX (for example an infinite scroll view)
  • The current implementation prevents a hrefs within the photoswipe gallery from working. For example when placing tag links on the image their click event is being prevented, which should not happen.

Both fixed have been tested in several cases and live in production. Please review and commit.

Comments

Anybody created an issue. See original summary.

anybody’s picture

Status: Active » Needs review
StatusFileSize
new4.17 KB

Patch attached :)
Edit: Contains debug output. Use -3.

anybody’s picture

StatusFileSize
new4.12 KB

Correct patch attached. The other contained debug output, sorry.

anybody’s picture

Title: JavaScript bugs: context and other links (a href) within gallery handling » Fix JS context & link (a href) handling within gallery
anybody’s picture

StatusFileSize
new2.11 KB

Sorry I had some patch format issues -.-

anybody’s picture

StatusFileSize
new2.51 KB

One more addition to ensure there is no double event bindung in AJAX / context cases.

thomas.frobieter’s picture

Status: Needs review » Reviewed & tested by the community

#6 is working properly! RTBC.

anybody’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new3.61 KB

I finally did a complete code cleanup now. @thomas.frobieter would you be so nice to review that again? Patch attached.

thomas.frobieter’s picture

Status: Needs review » Reviewed & tested by the community

It's still working perfectly!

sun’s picture

Patch still applies and doesn't look wrong to me, but as I didn't run into the stated problems, I'd like to wait for further confirmations before committing it.

sun’s picture

+++ b/js/photoswipe.jquery.js
@@ -22,26 +35,14 @@
-        $galleries.each( function (index) {
+        $galleries.once('photoswipe').each(function (index) {

.once() and .each() are substitutes — I believe you should only call one of both, but not both.

With .once(), you can pass the usual iteration callback as the second argument.

However, the jQuery result set is still filtered by .once(), so calling both in a chain is not wrong, just suboptimal, so leaving RTBC.

  • sun committed dada18a on 8.x-1.x authored by Anybody
    Issue #2908894 by Anybody, thomas.frobieter, sun: Fixed links in...
sun’s picture

Status: Reviewed & tested by the community » Fixed

After studying this patch in more detail, it actually makes a lot of sense.

Thanks for reporting, contributing, patching, testing, and confirming! Committed to 8.x-1.x.

anybody’s picture

Thank you, sun! :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.