document.addEventListener("DOMContentLoaded", (event) => { // written with Gemini. Logic was built by me /** * Initializes a custom vertical thumbnail slider linked to an Elementor Swiper carousel. * Waits for CSS rendering and Swiper initialization before executing. */ function akInitVerticalThumbnails(sliderSelector = '.ak-vertical-thumbnails-slider') { const sliderContainer = document.querySelector(sliderSelector); if (!sliderContainer) return; // Exit silently if slider isn't on this page // --- THE "WAIT FOR RENDER" CHECKER --- const checkReady = () => { const swiperElement = sliderContainer.querySelector('.swiper'); // 1. Check if Elementor has physically painted the layout (height > 10px) const isRendered = sliderContainer.offsetHeight > 10; // 2. Check if the Swiper JavaScript object is officially attached const isSwiperReady = swiperElement && swiperElement.swiper; if (isRendered && isSwiperReady) { // Both are true! Build the thumbnails. buildThumbnails(sliderContainer, swiperElement.swiper); } else { // Not ready yet. Check again in 50 milliseconds. setTimeout(checkReady, 50); } }; // Start checking immediately checkReady(); // --- THE MAIN LOGIC (Only runs when ready) --- function buildThumbnails(container, swiper) { // 1. Get all the swiper images const images = Array.from(container.querySelectorAll('.elementor-carousel-image')) .map(slide => slide.style.backgroundImage.replace(/^url\(["']?/, '').replace(/["']?\)$/, '')); if (images.length === 0) return; // 2 & 3. Render HTML and prepend the container const thumbsHTML = images.map((url, index) => `