From b9e436209a22ef6fabf19a466c1ace037b9c9f5f Mon Sep 17 00:00:00 2001 From: Jan Umbach Date: Tue, 28 May 2024 17:11:08 +0200 Subject: [PATCH] test --- assets/global.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/assets/global.js b/assets/global.js index 85675c4..b07b43e 100644 --- a/assets/global.js +++ b/assets/global.js @@ -1124,14 +1124,30 @@ class VariantSelects extends HTMLElement { const mediaGalleries = document.querySelectorAll(`[id^="MediaGallery-${this.dataset.section}"]`); mediaGalleries.forEach((mediaGallery) => { - mediaGallery.setActiveMedia(`${this.dataset.section}-${this.currentVariant.featured_media.id}`, true); + //mediaGallery.setActiveMedia(`${this.dataset.section}-${this.currentVariant.featured_media.id}`, true); // how to get second image id from the gallery console.log('mediaGallery', mediaGallery); // get the second image id - const secondImageId = mediaGallery.querySelector('.thumbnail-list__item:nth-child(2)').dataset; - console.log('secondImageId', secondImageId); + const galleryImages = mediaGallery.querySelectorAll('.thumbnail-list__item:nth-child(2)').dataset; + + for (const galleryImage of galleryImages) { + // if display is not none, then show the image + if (galleryImage.style.display !== 'none') { + + + + const target = galleryImage.target; // "template--22806669590804__main-38794319626516" + const targetId = target.split('__')[1]; // "main-38794319626516" + const targetIdSplit = targetId.split('-')[1]; // "38794319626516" + + mediaGallery.setActiveMedia(`${this.dataset.section}-${targetIdSplit}`, true); + + } + + } +