Baseline - Eddys Nova Estrutura
This commit is contained in:
+178
@@ -0,0 +1,178 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
/* ==========================================
|
||||
PRELOADER (Correção Blindada)
|
||||
========================================== */
|
||||
/* Preloader Blindado contra Travamento */
|
||||
const preload = document.getElementById('preload');
|
||||
if (preload) {
|
||||
const hidePreloader = () => {
|
||||
preload.classList.add('completed');
|
||||
setTimeout(() => {
|
||||
preload.style.display = 'none';
|
||||
}, 500);
|
||||
};
|
||||
|
||||
if (document.readyState === 'complete') {
|
||||
hidePreloader();
|
||||
} else {
|
||||
window.addEventListener('load', hidePreloader);
|
||||
// Fallback de segurança absoluto: remove a capa em 1 segundo
|
||||
setTimeout(hidePreloader, 1000);
|
||||
}
|
||||
}
|
||||
/* ==========================================
|
||||
MENU MOBILE TOGGLE
|
||||
========================================== */
|
||||
const mobileToggle = document.getElementById('mobile-toggle');
|
||||
const mainNav = document.getElementById('main-nav');
|
||||
|
||||
if (mobileToggle && mainNav) {
|
||||
mobileToggle.addEventListener('click', () => {
|
||||
mainNav.classList.toggle('active');
|
||||
mobileToggle.classList.toggle('open');
|
||||
|
||||
// Acessibilidade: atualiza o estado do botão
|
||||
const isExpanded = mobileToggle.getAttribute('aria-expanded') === 'true';
|
||||
mobileToggle.setAttribute('aria-expanded', !isExpanded);
|
||||
});
|
||||
}
|
||||
|
||||
/* ==========================================
|
||||
SUBMENUS MOBILE
|
||||
========================================== */
|
||||
const parentMenuItems = document.querySelectorAll('.menu-item-has-children > a');
|
||||
parentMenuItems.forEach(item => {
|
||||
item.addEventListener('click', (e) => {
|
||||
if (window.innerWidth <= 991) {
|
||||
e.preventDefault();
|
||||
const parent = item.parentElement;
|
||||
parent.classList.toggle('open');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/* ==========================================
|
||||
HERO SLIDER (HOME)
|
||||
========================================== */
|
||||
const slides = document.querySelectorAll('.hero-slider .slide');
|
||||
const prevBtnHome = document.getElementById('prevSlide');
|
||||
const nextBtnHome = document.getElementById('nextSlide');
|
||||
const dotsContainer = document.getElementById('sliderDots');
|
||||
let currentHomeSlide = 0;
|
||||
let homeSlideInterval;
|
||||
|
||||
if (slides.length > 0) {
|
||||
// Cria os pontos (dots) de navegação dinamicamente
|
||||
slides.forEach((_, idx) => {
|
||||
const dot = document.createElement('button');
|
||||
dot.classList.add('dot');
|
||||
dot.setAttribute('aria-label', `Go to slide ${idx + 1}`);
|
||||
if (idx === 0) dot.classList.add('active');
|
||||
dot.addEventListener('click', () => goToHomeSlide(idx));
|
||||
if (dotsContainer) dotsContainer.appendChild(dot);
|
||||
});
|
||||
|
||||
const dots = document.querySelectorAll('.slider-dots .dot');
|
||||
|
||||
function goToHomeSlide(n) {
|
||||
slides[currentHomeSlide].classList.remove('active');
|
||||
if (dots[currentHomeSlide]) dots[currentHomeSlide].classList.remove('active');
|
||||
|
||||
currentHomeSlide = (n + slides.length) % slides.length;
|
||||
|
||||
slides[currentHomeSlide].classList.add('active');
|
||||
if (dots[currentHomeSlide]) dots[currentHomeSlide].classList.add('active');
|
||||
|
||||
resetHomeAutoplay();
|
||||
}
|
||||
|
||||
function nextHomeSlide() {
|
||||
goToHomeSlide(currentHomeSlide + 1);
|
||||
}
|
||||
|
||||
function prevHomeSlide() {
|
||||
goToHomeSlide(currentHomeSlide - 1);
|
||||
}
|
||||
|
||||
if (nextBtnHome) nextBtnHome.addEventListener('click', nextHomeSlide);
|
||||
if (prevBtnHome) prevBtnHome.addEventListener('click', prevHomeSlide);
|
||||
|
||||
function startHomeAutoplay() {
|
||||
homeSlideInterval = setInterval(nextHomeSlide, 5000);
|
||||
}
|
||||
|
||||
function resetHomeAutoplay() {
|
||||
clearInterval(homeSlideInterval);
|
||||
startHomeAutoplay();
|
||||
}
|
||||
|
||||
startHomeAutoplay();
|
||||
|
||||
// Pausa o autoplay quando o usuário passa o mouse sobre o slider
|
||||
const heroSlider = document.querySelector('.hero-slider');
|
||||
if (heroSlider) {
|
||||
heroSlider.addEventListener('mouseenter', () => clearInterval(homeSlideInterval));
|
||||
heroSlider.addEventListener('mouseleave', startHomeAutoplay);
|
||||
}
|
||||
}
|
||||
|
||||
/* ==========================================
|
||||
GALERIA DE SERVIÇOS (Se existir na página)
|
||||
========================================== */
|
||||
const galleryTrack = document.getElementById('galleryTrack');
|
||||
const thumbs = document.querySelectorAll('.service-gallery-thumbs img');
|
||||
const prevBtnGallery = document.getElementById('galleryPrev');
|
||||
const nextBtnGallery = document.getElementById('galleryNext');
|
||||
|
||||
if (galleryTrack && thumbs.length > 0) {
|
||||
let currentGalleryIndex = 0;
|
||||
|
||||
function updateGallery(index) {
|
||||
currentGalleryIndex = (index + thumbs.length) % thumbs.length;
|
||||
galleryTrack.style.transform = `translateX(-${currentGalleryIndex * 100}%)`;
|
||||
thumbs.forEach((thumb, idx) => {
|
||||
thumb.classList.toggle('active', idx === currentGalleryIndex);
|
||||
});
|
||||
}
|
||||
|
||||
if (nextBtnGallery) {
|
||||
nextBtnGallery.addEventListener('click', () => updateGallery(currentGalleryIndex + 1));
|
||||
}
|
||||
if (prevBtnGallery) {
|
||||
prevBtnGallery.addEventListener('click', () => updateGallery(currentGalleryIndex - 1));
|
||||
}
|
||||
thumbs.forEach((thumb, idx) => {
|
||||
thumb.addEventListener('click', () => updateGallery(idx));
|
||||
});
|
||||
}
|
||||
|
||||
/* ==========================================
|
||||
FORMULÁRIO DE CONTATO COM REDIRECIONAMENTO
|
||||
========================================== */
|
||||
const contactForm = document.getElementById('contact-form');
|
||||
const responseContainer = document.getElementById('contact-content');
|
||||
|
||||
if (contactForm && responseContainer) {
|
||||
contactForm.addEventListener('submit', (e) => {
|
||||
e.preventDefault();
|
||||
const formData = new FormData(contactForm);
|
||||
responseContainer.innerHTML = '<div class="thanks loading">Sending message...</div>';
|
||||
|
||||
fetch(contactForm.getAttribute('action'), {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.text())
|
||||
.then(data => {
|
||||
if (data.trim() === 'REDIRECT:thankyou.html') {
|
||||
window.location.href = 'thankyou.html';
|
||||
} else {
|
||||
responseContainer.innerHTML = data;
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
responseContainer.innerHTML = '<div class="thanks failure">An error occurred while sending your message. Please try again.</div>';
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user