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.

Comments

iKristjan created an issue. See original summary.

iKristjan’s picture

Assigned: iKristjan » Unassigned
Status: Active » Needs review
StatusFileSize
new671 bytes

Status: Needs review » Needs work

The last submitted patch, photoswipe-links-without-img-fix-3023442-2.patch, failed testing. View results

iKristjan’s picture

iKristjan’s picture

gobinathm’s picture

Status: Needs work » Active
iKristjan’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 5: photoswipe-links-without-img-fix-3023442-5.patch, failed testing. View results

anybody’s picture

Status: Needs work » Fixed

Reviewed, rewritten and committed this edge case. Thanks!

  • Anybody committed 6245f0f on 7.x-2.x
    Issue #3023442 by iKristjan, Anybody: Links without thumbnails not...

Status: Fixed » Closed (fixed)

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