Problem/Motivation
Zoom Animation feature (https://www.drupal.org/project/photoswipe/issues/2494869), which also got added into the latest release 7.x-2.0-beta4 (at 28 December 2018), introduced a bug that's triggered when <a class="photoswipe"> elements don't include a child <img> (e.g. thumbnail image) element. Clicking a link like that throws the following JavaScript error:
[Error] TypeError: undefined is not an object (evaluating 'tpos.left')
getThumbBoundsFn (photoswipe.jquery.js:118)
(anonymous function) (photoswipe.min.js:4:25037)
Cb (photoswipe.min.js:4:4141)
init (photoswipe.min.js:4:8412)
openPhotoSwipe (photoswipe.jquery.js:123)
onThumbnailsClick (photoswipe.jquery.js:73)
dispatch (jquery.min.js:3:8555)
handle (jquery.min.js:3:5258)
Proposed resolution
My working fix is adding a check to the new "options.getThumbBoundsFn" function (specifically to line 112 in photoswipe.jquery.js), which would return undefined if there's no image and hence would not try to get offset of an img element that doesn't exist:
if (tn.length === 0) {
return undefined;
}
Remaining tasks
I'll provide a patch.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | photoswipe-links-without-img-fix-3023442-5.patch | 669 bytes | iKristjan |
Comments
Comment #2
iKristjan commentedComment #4
iKristjan commentedComment #5
iKristjan commentedComment #6
gobinathmComment #7
iKristjan commentedComment #9
anybodyReviewed, rewritten and committed this edge case. Thanks!