From 4d6b65f63c4eae5b4b8dfaf117bf66d747a4c1cc Mon Sep 17 00:00:00 2001 From: Jimmy Cai Date: Mon, 5 Feb 2024 17:43:25 +0100 Subject: [PATCH] fix: PhotoSwipe not getting the real image dimensions This is because `img.width.toString()` returns the `` element dimension, not the real image dimension (stored in the `width` attribute). closes https://github.com/CaiJimmy/hugo-theme-stack/issues/934 --- assets/ts/gallery.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/ts/gallery.ts b/assets/ts/gallery.ts index e0124d1..e60c006 100644 --- a/assets/ts/gallery.ts +++ b/assets/ts/gallery.ts @@ -61,8 +61,8 @@ export default (container: HTMLElement) => { const a = document.createElement('a'); a.href = img.src; a.setAttribute('target', '_blank'); - a.setAttribute('data-pswp-width', img.width.toString()); - a.setAttribute('data-pswp-height', img.height.toString()); + a.setAttribute('data-pswp-width', img.getAttribute('width')); + a.setAttribute('data-pswp-height', img.getAttribute('height')); img.parentNode.insertBefore(a, img); a.appendChild(img); }