ruạṛ
/** * Innovative Equipment - Main JavaScript */ document.addEventListener('DOMContentLoaded', function () { // ===== STICKY HEADER SCROLL EFFECT ===== const header = document.getElementById('site-header'); if (header) { window.addEventListener('scroll', function () { header.classList.toggle('scrolled', window.scrollY > 50); }); } // ===== MOBILE MENU TOGGLE ===== const menuToggle = document.getElementById('menu-toggle'); const mainNav = document.getElementById('main-nav'); if (menuToggle && mainNav) { menuToggle.addEventListener('click', function () { menuToggle.classList.toggle('active'); mainNav.classList.toggle('active'); }); // Close when clicking a link mainNav.querySelectorAll('a').forEach(function (link) { link.addEventListener('click', function () { menuToggle.classList.remove('active'); mainNav.classList.remove('active'); }); }); } // ===== SCROLL REVEAL ANIMATIONS ===== const revealElements = document.querySelectorAll('.reveal'); if (revealElements.length > 0) { const revealObserver = new IntersectionObserver(function (entries) { entries.forEach(function (entry) { if (entry.isIntersecting) { entry.target.classList.add('visible'); revealObserver.unobserve(entry.target); } }); }, { threshold: 0.1, rootMargin: '0px 0px -50px 0px' }); revealElements.forEach(function (el) { revealObserver.observe(el); }); } // ===== AJAX FORM SUBMISSIONS ===== // Supply ASAP Form const supplyForm = document.getElementById('supply-form'); if (supplyForm) { supplyForm.addEventListener('submit', function (e) { e.preventDefault(); submitForm(supplyForm, 'ie_supply_asap', 'supply-success'); }); } // Get Quote Form const quoteForm = document.getElementById('quote-form'); if (quoteForm) { quoteForm.addEventListener('submit', function (e) { e.preventDefault(); submitForm(quoteForm, 'ie_get_quote', 'quote-success'); }); } // Contact Form const contactForm = document.getElementById('contact-form'); if (contactForm) { contactForm.addEventListener('submit', function (e) { e.preventDefault(); submitForm(contactForm, 'ie_contact_form', 'contact-success'); }); } }); // ===== MODAL FUNCTIONS ===== function openModal(type, productName, partNumber) { var modal = document.getElementById(type + '-modal'); var overlay = document.getElementById(type + '-overlay'); var nameField = document.getElementById(type + '-product-name'); var partField = document.getElementById(type + '-part-number'); if (nameField) nameField.value = productName || ''; if (partField) partField.value = partNumber || ''; if (modal) modal.classList.add('active'); if (overlay) overlay.classList.add('active'); document.body.style.overflow = 'hidden'; // Close on overlay click if (overlay) { overlay.onclick = function () { closeModal(type); }; } } function closeModal(type) { var modal = document.getElementById(type + '-modal'); var overlay = document.getElementById(type + '-overlay'); if (modal) modal.classList.remove('active'); if (overlay) overlay.classList.remove('active'); document.body.style.overflow = ''; } // Close modals with Escape key document.addEventListener('keydown', function (e) { if (e.key === 'Escape') { closeModal('supply'); closeModal('quote'); } }); // ===== AJAX FORM SUBMISSION ===== function submitForm(form, action, successId) { var submitBtn = form.querySelector('button[type="submit"]'); var originalText = submitBtn ? submitBtn.textContent : ''; if (submitBtn) { submitBtn.disabled = true; submitBtn.textContent = 'Sending...'; } var formData = new FormData(form); formData.append('action', action); formData.append('nonce', (typeof ieAjax !== 'undefined') ? ieAjax.nonce : ''); var ajaxUrl = (typeof ieAjax !== 'undefined') ? ieAjax.ajaxurl : '/wp-admin/admin-ajax.php'; fetch(ajaxUrl, { method: 'POST', body: formData, }) .then(function (response) { return response.json(); }) .then(function (data) { if (data.success) { form.style.display = 'none'; var successEl = document.getElementById(successId); if (successEl) successEl.style.display = 'block'; } else { alert(data.data || 'Something went wrong. Please try again.'); } }) .catch(function () { alert('Network error. Please call us on 0274 321 966.'); }) .finally(function () { if (submitBtn) { submitBtn.disabled = false; submitBtn.textContent = originalText; } }); }
cải xoăn