document.addEventListener('DOMContentLoaded', () => { const quoteForm = document.getElementById('quoteForm'); const toastEl = document.getElementById('quoteToast'); const nav = document.getElementById('mainNav'); const navToggle = document.querySelector('[data-bs-target="#mainNav"]'); const hasBootstrap = Boolean(window.bootstrap); if (nav && navToggle && !hasBootstrap) { navToggle.addEventListener('click', () => { const isOpen = nav.classList.toggle('show'); navToggle.setAttribute('aria-expanded', isOpen ? 'true' : 'false'); }); } if (toastEl && hasBootstrap) { window.bootstrap.Toast.getOrCreateInstance(toastEl, { delay: 5200 }).show(); } document.querySelectorAll('a[href^="#"]').forEach((link) => { link.addEventListener('click', () => { if (nav && nav.classList.contains('show')) { if (hasBootstrap) { window.bootstrap.Collapse.getOrCreateInstance(nav).hide(); } else { nav.classList.remove('show'); navToggle?.setAttribute('aria-expanded', 'false'); } } }); }); if (!quoteForm) return; quoteForm.addEventListener('submit', (event) => { const brief = quoteForm.querySelector('#message'); const submitButton = quoteForm.querySelector('button[type="submit"]'); if (brief && brief.value.trim().length < 20) { brief.setCustomValidity('Share at least 20 characters about the project.'); } else if (brief) { brief.setCustomValidity(''); } if (!quoteForm.checkValidity()) { event.preventDefault(); event.stopPropagation(); const firstInvalid = quoteForm.querySelector(':invalid'); if (firstInvalid) firstInvalid.focus({ preventScroll: false }); } else if (submitButton) { submitButton.disabled = true; submitButton.textContent = 'Sending…'; } quoteForm.classList.add('was-validated'); }); });