// ============================================================ // PATCH PARA: Carrossel (Swiper) + Accordion (Q&A) do Elementor // COMO USAR: Cole o conteúdo desta tag document.addEventListener('DOMContentLoaded', function() { // ===== FIX 1: ACCORDION (Q&A) ===== // Esconde todos os conteúdos inicialmente document.querySelectorAll('.elementor-tab-content').forEach(function(c) { c.style.display = 'none'; }); // Adiciona toggle ao clicar em cada pergunta document.querySelectorAll('.elementor-tab-title').forEach(function(title) { title.style.cursor = 'pointer'; title.addEventListener('click', function() { var tabNum = this.getAttribute('data-tab'); var contentId = 'elementor-tab-content-163' + tabNum; var content = document.getElementById(contentId); var isOpen = this.getAttribute('aria-expanded') === 'true'; // Fecha todos document.querySelectorAll('.elementor-tab-title').forEach(function(t) { t.setAttribute('aria-expanded', 'false'); t.classList.remove('elementor-active'); }); document.querySelectorAll('.elementor-tab-content').forEach(function(c) { c.style.display = 'none'; }); // Se estava fechado, abre if (!isOpen && content) { this.setAttribute('aria-expanded', 'true'); this.classList.add('elementor-active'); content.style.display = 'block'; } }); }); // ===== FIX 2: CARROSSEL (Swiper manual) ===== var wrapper = document.querySelector('.elementor-image-carousel .swiper-wrapper'); if (!wrapper) return; var slides = wrapper.querySelectorAll('.swiper-slide'); if (!slides.length) return; var current = 0; // Força carregamento de TODAS as imagens (bypassa lazy load do LiteSpeed) slides.forEach(function(slide) { var img = slide.querySelector('img'); if (img) { var dataSrc = img.getAttribute('data-src'); if (dataSrc && !dataSrc.startsWith('data:')) { img.src = dataSrc; } else if (img.src && img.src.startsWith('data:')) { var srcset = img.getAttribute('srcset') || img.getAttribute('data-srcset'); if (srcset) { var firstUrl = srcset.split(',')[0].trim().split(' ')[0]; if (firstUrl && !firstUrl.startsWith('data:')) img.src = firstUrl; } } } var source = slide.querySelector('source'); if (source) { var srcset = source.getAttribute('srcset') || source.getAttribute('data-srcset'); if (srcset) source.srcset = srcset; } }); // Container com overflow hidden var container = wrapper.closest('.elementor-image-carousel-wrapper'); if (container) { container.style.overflow = 'hidden'; container.style.position = 'relative'; } // Wrapper como flex row wrapper.style.display = 'flex'; wrapper.style.transition = 'transform 0.5s ease'; wrapper.style.willChange = 'transform'; // Cada slide = 100% da largura slides.forEach(function(slide) { slide.style.minWidth = '100%'; slide.style.flexShrink = '0'; slide.style.boxSizing = 'border-box'; }); // Dots de paginação var pagination = document.querySelector('.swiper-pagination'); if (pagination) { pagination.innerHTML = ''; pagination.style.cssText = 'text-align:center;padding:8px 0;'; slides.forEach(function(_, i) { var dot = document.createElement('span'); dot.dataset.index = i; dot.style.cssText = 'display:inline-block;width:10px;height:10px;border-radius:50%;background:#ccc;margin:0 4px;cursor:pointer;transition:background 0.3s;'; dot.addEventListener('click', function() { goTo(parseInt(this.dataset.index)); }); pagination.appendChild(dot); }); } function updateDots() { if (!pagination) return; pagination.querySelectorAll('span').forEach(function(dot, i) { dot.style.background = i === current ? '#555' : '#ccc'; }); } function goTo(index) { if (index < 0) index = slides.length - 1; if (index >= slides.length) index = 0; current = index; wrapper.style.transform = 'translateX(-' + (current * 100) + '%)'; updateDots(); } // Botões prev / next var btnPrev = document.querySelector('.elementor-swiper-button-prev'); var btnNext = document.querySelector('.elementor-swiper-button-next'); if (btnPrev) { btnPrev.style.cursor = 'pointer'; btnPrev.addEventListener('click', function() { goTo(current - 1); }); } if (btnNext) { btnNext.style.cursor = 'pointer'; btnNext.addEventListener('click', function() { goTo(current + 1); }); } // Swipe no mobile var touchStartX = 0; wrapper.addEventListener('touchstart', function(e) { touchStartX = e.touches[0].clientX; }, {passive: true}); wrapper.addEventListener('touchend', function(e) { var diff = touchStartX - e.changedTouches[0].clientX; if (Math.abs(diff) > 40) goTo(diff > 0 ? current + 1 : current - 1); }); // Autoplay 5s + pausa no hover var autoplay = setInterval(function() { goTo(current + 1); }, 5000); wrapper.addEventListener('mouseenter', function() { clearInterval(autoplay); }); wrapper.addEventListener('mouseleave', function() { autoplay = setInterval(function() { goTo(current + 1); }, 5000); }); goTo(0); });