dimsemenov / PhotoSwipe

JavaScript image gallery for mobile and desktop, modular, framework independent
http://photoswipe.com
MIT License
24.18k stars 3.31k forks source link

Photoswipe won't close if image has no thumb #1232

Open cursorblinkrate opened 7 years ago

cursorblinkrate commented 7 years ago

Following the examples on http://photoswipe.com/documentation/seo.html I tried the part describing the use without thumbnails (using code snippet below "If you don't want thumbnails to be visible on page, e.g. you have 50 images in gallery and you show just first 3 thumbnails + link"), the images take part of the photoswipe gallery and I can nicely switch between them.

But if I try to close photo swipe (e.g. using the x in the top right corner, ESC key), when an image that has no thumbnail is displayed, then I can't close photo swipe anymore. Its worse, after it doesn't close, it won't accept any onther input, so you can't switch between images or anything.

After a little investigation with the browser's error console, I noticed that the problem comes from a null reference in the example code from http://photoswipe.com/documentation/getting-started.html below the Headling "How to build an array of slides from a list of links". In the function getThumbBoundsFn: function(index) { the problem occures at rect = thumbnail.getBoundingClientRect();.

The code can be fixed with a check for the variable thumbnail being not null and, if not, choosing an arbitrary rectangle. I guess I'm not the only one using the example code, so I think it would be great to fix the example :-).

P.S.: PhotoSwipe is great! Thanks for maintaning it.

mjau-mjau commented 7 years ago

Works fine here ... you can find several examples of popup links without thumbnails here: https://demo.flamepix.com/examples/plugins/popup/

In your Photoswipe options, you should probably make sure that you have the following options if you don't have thumbnails:

showHideOpacity: true,
getThumbBoundsFn: false

Normally, getThumbBoundsFn would be undefined by default, but perhaps it is set in your code somehow?