File size: 2,345 Bytes
2f590d3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
// Utility: query helpers
const $ = (sel, ctx = document) => ctx.querySelector(sel);
const $$ = (sel, ctx = document) => Array.from(ctx.querySelectorAll(sel));
// Mobile navigation toggle
const menuBtn = $('#menuBtn');
const mobileNav = $('#mobileNav');
if (menuBtn && mobileNav) {
menuBtn.addEventListener('click', () => {
const expanded = menuBtn.getAttribute('aria-expanded') === 'true';
menuBtn.setAttribute('aria-expanded', String(!expanded));
mobileNav.classList.toggle('hidden');
});
}
// Smooth scroll for in-page links
$$('a[href^="#"]').forEach(a => {
a.addEventListener('click', e => {
const href = a.getAttribute('href');
if (!href || href === '#') return;
const target = $(href);
if (target) {
e.preventDefault();
target.scrollIntoView({ behavior: 'smooth', block: 'start' });
// Close mobile menu after navigation
if (!mobileNav.classList.contains('hidden')) {
mobileNav.classList.add('hidden');
menuBtn.setAttribute('aria-expanded', 'false');
}
}
});
});
// Contact form handler
const form = $('#contactForm');
if (form) {
form.addEventListener('submit', async (e) => {
e.preventDefault();
const formData = new FormData(form);
const data = Object.fromEntries(formData.entries());
// Minimal client validation example
if (!data.email || !/^\S+@\S+\.\S+$/.test(data.email)) {
alert('Please enter a valid email.');
return;
}
if (!data.name || data.name.trim().length < 2) {
alert('Please enter your name.');
return;
}
if (!data.message || data.message.trim().length < 10) {
alert('Please enter a longer message (10+ characters).');
return;
}
// Simulated submit (replace with real fetch to your backend)
console.log('Submitting contact form:', data);
form.reset();
alert('Thanks! Your message has been sent.');
});
}
// Set footer year
const yearEl = $('#year');
if (yearEl) yearEl.textContent = String(new Date().getFullYear());
// Optional: Log Tailwind colors for quick inspection in dev
console.log('Primary 500:', getComputedStyle(document.documentElement).getPropertyValue('--tw-color-primary-500') || 'N/A');
console.log('Secondary 500:', getComputedStyle(document.documentElement).getPropertyValue('--tw-color-secondary-500') || 'N/A'); |