lightbox: Fix the panzoom access for non image.

Previously, when we load for the first time, the panzoom
control is binded by default to the image class.

This causes various problems like when a non image class
is opened first in lightbox, and some panzoom function
is performed on it, even though no panzoom object
is binded to them it would perform the function with
the object binded to image class, causing it to throw
errors when no image has been opened yet in the lightbox.

This is fixed by checking if the image class has an img tag
in it before performing any functions of the the panzoom
object.
This commit is contained in:
roanster007 2023-11-18 20:42:12 +05:30 committed by Tim Abbott
parent adc11e5ba2
commit 6397df8b5b
1 changed files with 12 additions and 0 deletions

View File

@ -91,6 +91,10 @@ export class PanZoomControl {
}
constrainImage(e) {
if (!this.isActive()) {
return;
}
// Instead of using panzoom's built in bounds option which was buggy
// at the time of this writing, we act on pan/zoom events and move the
// image back in to view if it is moved beyond the image-preview container.
@ -154,12 +158,20 @@ export class PanZoomControl {
}
zoomIn() {
if (!this.isActive()) {
return;
}
const w = $(".image-preview").width();
const h = $(".image-preview").height();
this.panzoom.smoothZoom(w / 2, h / 2, Math.SQRT2);
}
zoomOut() {
if (!this.isActive()) {
return;
}
const w = $(".image-preview").width();
const h = $(".image-preview").height();
this.panzoom.smoothZoom(w / 2, h / 2, Math.SQRT1_2);