1window.addEventListener('DOMContentLoaded', () => { 2 const upsellButtons = document.querySelectorAll('.upsell-collection-button'); 3 upsellButtons.forEach(button => { 4 button.addEventListener('click', () => { 5 // Get the product card container 6 const productCard = button.closest('.product-card'); 7 if (!productCard) return; 8 9 // Remove active class from all upsell buttons in this product card 10 const allUpsellButtons = productCard.querySelectorAll('.upsell-collection-button'); 11 allUpsellButtons.forEach(btn => btn.classList.remove('active')); 12 13 // Add active class to clicked button 14 button.classList.add('active'); 15 16 // Get the hidden price from inside the button 17 const hiddenPrice = button.querySelector('.hidden-price .price'); 18 if (!hiddenPrice) return; 19 20 // Get the visible price element in the product card 21 const visiblePrice = productCard.querySelector('p.font-bold .price'); 22 if (visiblePrice) { 23 // Preserve the inner HTML structure (strikes, styles, etc) 24 visiblePrice.innerHTML = hiddenPrice.innerHTML; 25 } 26 27 // Get the title from the button's data-title attribute 28 const newTitle = button.dataset.title; 29 if (newTitle) { 30 // Update the product card title 31 const titleElement = productCard.querySelector('h2 a'); 32 if (titleElement) { 33 titleElement.textContent = newTitle; 34 } 35 } 36 37 // Update the add-to-cart button's data-variant-id 38 const addToCartButton = productCard.querySelector('.add-to-cart'); 39 const newVariantId = button.dataset.variantId; 40 if (addToCartButton && newVariantId) { 41 addToCartButton.dataset.variantId = newVariantId; 42 } 43 44 // Update the main discount badge 45 const mainDiscountBadge = productCard.querySelector('a > .discount-badge'); 46 const buttonDiscountBadge = button.querySelector('.discount-badge'); 47 48 if (mainDiscountBadge && buttonDiscountBadge) { 49 // Get the discount text directly from the button's badge 50 const discountText = buttonDiscountBadge.textContent.trim(); 51 52 // Update the main badge content directly (it might not have a span) 53 mainDiscountBadge.textContent = discountText; 54 55 // Show/hide the main badge based on content 56 if (discountText !== '') { 57 mainDiscountBadge.classList.remove('hidden'); 58 } else { 59 mainDiscountBadge.classList.add('hidden'); 60 } 61 } 62 }); 63 }); 64 });
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.