← back to Goldleafwallpaper

site-shell.js

80 lines

// Goldleaf shared shell — header auto-hide + menu/contact/inquiry modals
(function(){
  // Header auto-hide (proven from Novasuede V4)
  const header = document.getElementById('siteHeader');
  if (header) {
    const REVEAL = 80;
    let hideT;
    function show(){ clearTimeout(hideT); document.body.classList.add('show-header'); }
    function scheduleHide(){
      clearTimeout(hideT);
      hideT = setTimeout(() => {
        if(header.matches(':hover')) return;
        if(header.contains(document.activeElement)) return;
        document.body.classList.remove('show-header');
      }, 200);
    }
    document.addEventListener('mousemove', e => {
      if(e.clientY < REVEAL || header.contains(e.target)) show();
      else scheduleHide();
    });
    document.addEventListener('focusin', e => { if(header.contains(e.target)) show(); });
    document.addEventListener('focusout', scheduleHide);
    document.addEventListener('touchstart', e => {
      const y = (e.touches && e.touches[0]) ? e.touches[0].clientY : 0;
      if(y < REVEAL || header.contains(e.target)) show();
      else scheduleHide();
    }, {passive:true});
    function syncScroll(){ if(window.scrollY < 4) show(); }
    window.addEventListener('scroll', syncScroll, {passive:true});
    syncScroll();
  }
})();

// Menu modal
function openMenuModal(){ document.getElementById('menuModal').classList.add('open'); }
function closeMenuModal(){ document.getElementById('menuModal').classList.remove('open'); }

// Contact options modal
function openContactMenu(){ document.getElementById('contactModal').classList.add('open'); }
function closeContactMenu(){ document.getElementById('contactModal').classList.remove('open'); }

// Inquiry modal + submit
function openInquiryModal(){ document.getElementById('inquiryModal').classList.add('open'); }
function closeInquiryModal(){ document.getElementById('inquiryModal').classList.remove('open'); }
function submitInquiry(e){
  e.preventDefault();
  const data = new FormData(e.target);
  const btn = document.getElementById('inquirySubmit');
  const status = document.getElementById('inquiryStatus');
  const payload = {
    name: data.get('name'), email: data.get('email'), phone: data.get('phone'),
    company: data.get('company'), projectName: data.get('projectName'),
    projectScope: data.get('projectScope'), message: data.get('message')
  };
  btn.disabled = true; btn.textContent = 'Sending…';
  status.style.display = 'none';
  fetch('/api/send-inquiry', {
    method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify(payload)
  }).then(r => { if(!r.ok) throw new Error('HTTP ' + r.status); return r.json(); })
  .then(() => {
    status.textContent = "Inquiry sent — we'll respond within 1 business day";
    status.style.color = '#9ad19a';
    status.style.display = 'block';
    btn.textContent = 'Sent ✓';
    setTimeout(closeInquiryModal, 2500);
  }).catch(() => {
    const subject = encodeURIComponent('Goldleaf Project Inquiry — ' + (payload.projectName||''));
    const body = encodeURIComponent(
      'Name: ' + (payload.name||'') + '\nEmail: ' + (payload.email||'') +
      '\nPhone: ' + (payload.phone||'') + '\nCompany: ' + (payload.company||'') +
      '\nProject Name: ' + (payload.projectName||'') +
      '\nProject Scope: ' + (payload.projectScope||'') +
      '\nNotes: ' + (payload.message||'')
    );
    window.location.href = 'mailto:info@goldleafwallpaper.com?subject=' + subject + '&body=' + body;
    btn.disabled = false; btn.textContent = 'Send Inquiry';
  });
  return false;
}