68 lines
2.3 KiB
Plaintext
68 lines
2.3 KiB
Plaintext
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
/* Preloader */
|
|
const preload = document.getElementById('preload');
|
|
if (preload) {
|
|
window.addEventListener('load', () => {
|
|
preload.style.opacity = '0';
|
|
preload.style.transition = 'opacity 0.4s ease';
|
|
setTimeout(() => {
|
|
preload.style.display = 'none';
|
|
}, 400);
|
|
});
|
|
}
|
|
|
|
/* 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');
|
|
});
|
|
}
|
|
|
|
/* 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');
|
|
}
|
|
});
|
|
});
|
|
|
|
/* 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>';
|
|
});
|
|
});
|
|
}
|
|
|
|
});
|