1frappe.ready(function() { 2 // Only run on product pages 3 if (!window.location.pathname.includes('/products/')) return; 4 5 // Configuration 6 const AUTOPLAY_INTERVAL = 4000; // 4 seconds between images 7 let autoplayTimer = null; 8 let currentIndex = 0; 9 let isPaused = false; 10 11 function startAutoplay() { 12 // Find all slideshow thumbnail images 13 const thumbnails = document.querySelectorAll('.item-slideshow-image'); 14 15 if (thumbnails.length <= 1) return; // No slideshow if only 1 image 16 17 console.log('Starting image autoplay with', thumbnails.length, 'images'); 18 19 autoplayTimer = setInterval(function() { 20 if (isPaused) return; 21 22 // Move to next image 23 currentIndex = (currentIndex + 1) % thumbnails.length; 24 25 // Click the thumbnail to change main image 26 thumbnails[currentIndex].click(); 27 28 console.log('Auto-switched to image', currentIndex + 1, 'of', thumbnails.length); 29 }, AUTOPLAY_INTERVAL); 30 } 31 32 // Pause autoplay when user hovers over images 33 function setupHoverPause() { 34 const imageContainer = document.querySelector('.item-slideshow, .product-image-wrapper'); 35 36 if (imageContainer) { 37 imageContainer.addEventListener('mouseenter', function() { 38 isPaused = true; 39 console.log('Autoplay paused'); 40 }); 41 42 imageContainer.addEventListener('mouseleave', function() { 43 isPaused = false; 44 console.log('Autoplay resumed'); 45 }); 46 } 47 } 48 49 // MKT2-LCP (WEEKEND-001 / MKT-001 perf §2): gate autoplay start on the FIRST 50 // user interaction (pointerdown/touchstart/keydown/wheel) OR a 15 s fallback. 51 // The previous load+4s timer was not enough: browsers keep observing LCP until 52 // the first interaction/scroll, so a timer-driven gallery swap still re-armed 53 // LCP with the swapped view (suite-2 median PDP LCP element was the autoplay- 54 // swapped Back image). After a real interaction LCP is frozen, so rotation can 55 // never re-trigger it; the 15 s fallback keeps the gallery alive for passive 56 // viewers, far past any LCP measurement window. 57 const ARM_EVENTS = ['pointerdown', 'touchstart', 'keydown', 'wheel']; 58 let autoplayArmed = false; 59 60 function beginAutoplay() { 61 if (autoplayArmed) return; // idempotent â may fire once per arm event 62 autoplayArmed = true; 63 startAutoplay(); 64 setupHoverPause(); 65 } 66 67 ARM_EVENTS.forEach(function(evt) { 68 window.addEventListener(evt, beginAutoplay, { once: true, passive: true }); 69 }); 70 setTimeout(beginAutoplay, 15000); 71});
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.