Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/js/core/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,19 @@ class PhotoSwipeBase extends Eventable {
itemData.srcset = linkEl.dataset.pswpSrcset;
}

itemData.width = linkEl.dataset.pswpWidth ? parseInt(linkEl.dataset.pswpWidth, 10) : 0;
itemData.height = linkEl.dataset.pswpHeight ? parseInt(linkEl.dataset.pswpHeight, 10) : 0;
const thumbnailEl = element.querySelector('img');
// set itemData.w & itemData.h with naturalWidth & naturalHeight by default
itemData.width = thumbnailEl?.naturalWidth;
itemData.height = thumbnailEl?.naturalHeight;

// if pswp-width & pswp-height are defined, replace naturalWidth & naturalHeight with the defined pswp data
if (linkEl.dataset.pswpWidth) {
itemData.width = parseInt(linkEl.dataset.pswpWidth, 10);
}

if (linkEl.dataset.pswpHeight) {
itemData.height = parseInt(linkEl.dataset.pswpHeight, 10);
}

// support legacy w & h properties
itemData.w = itemData.width;
Expand All @@ -154,8 +165,6 @@ class PhotoSwipeBase extends Eventable {
itemData.type = linkEl.dataset.pswpType;
}

const thumbnailEl = element.querySelector('img');

if (thumbnailEl) {
// msrc is URL to placeholder image that's displayed before large image is loaded
// by default it's displayed only for the first slide
Expand Down