pull/1/head
Jan Umbach 2024-05-28 17:11:08 +02:00
parent 30175b02e3
commit b9e436209a
1 changed files with 19 additions and 3 deletions

View File

@ -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);
}
}