/* Darksteel Technologies — nav, scroll-reveal, contact form. No dependencies. */ (function () { // ---- Mobile nav ---- var header = document.getElementById('siteHeader'); var toggle = document.getElementById('navToggle'); if (toggle && header) { toggle.addEventListener('click', function () { var open = header.classList.toggle('open'); toggle.setAttribute('aria-expanded', open ? 'true' : 'false'); }); } // ---- Scroll reveal ---- var reveals = document.querySelectorAll('.reveal'); if ('IntersectionObserver' in window && reveals.length) { var io = new IntersectionObserver(function (entries) { entries.forEach(function (e) { if (e.isIntersecting) { e.target.classList.add('in'); io.unobserve(e.target); } }); }, { threshold: 0.12, rootMargin: '0px 0px -40px 0px' }); reveals.forEach(function (el) { io.observe(el); }); } else { reveals.forEach(function (el) { el.classList.add('in'); }); } // ---- Contact form ---- var CONTACT_ENDPOINT = window.CONTACT_ENDPOINT || ''; var form = document.getElementById('contactForm'); if (!form) return; var statusEl = document.getElementById('formStatus'); var btn = document.getElementById('submitBtn'); function setStatus(kind, msg) { if (statusEl) { statusEl.className = 'form-status show ' + kind; statusEl.textContent = msg; } } form.addEventListener('submit', function (e) { e.preventDefault(); if (form.website && form.website.value) { return; } // honeypot var data = { firstName: form.firstName.value.trim(), lastName: form.lastName.value.trim(), email: form.email.value.trim(), company: form.company ? form.company.value.trim() : '', message: form.message.value.trim() }; if (!data.firstName || !data.lastName || !data.email || !data.message) { setStatus('err', 'Please fill in your name, email, and a message.'); return; } if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(data.email)) { setStatus('err', 'Please enter a valid email address.'); return; } if (!CONTACT_ENDPOINT) { var subject = encodeURIComponent('Website inquiry from ' + data.firstName + ' ' + data.lastName); var body = encodeURIComponent('Name: ' + data.firstName + ' ' + data.lastName + '\nEmail: ' + data.email + '\n' + (data.company ? 'Company: ' + data.company + '\n' : '') + '\n' + data.message); window.location.href = 'mailto:info@darksteeltechnologies.com?subject=' + subject + '&body=' + body; setStatus('ok', 'Opening your email app to send the message…'); return; } btn.disabled = true; var original = btn.textContent; btn.textContent = 'Sending…'; fetch(CONTACT_ENDPOINT, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(function (r) { if (!r.ok) throw new Error(r.status); return r.json().catch(function () { return {}; }); }) .then(function () { form.reset(); setStatus('ok', 'Thanks — your message is on its way. We\'ll be in touch shortly.'); }) .catch(function () { setStatus('err', 'Something went wrong. Please email info@darksteeltechnologies.com or call (888) 501-5621.'); }) .finally(function () { btn.disabled = false; btn.textContent = original; }); }); })();