patx/rcraft_const

Scroll mobile enquiry links directly to contact form

Commit ef1c4a8 · patx · 2026-09-10T13:23:39-04:00

Changeset
ef1c4a895331b8190322536e2e72f26be1725339
Parents
0c84cbd8eb29280bf023f0be37268ed8ab883538

View source at this commit

Comments

No comments yet.

Log in to comment

Diff

diff --git a/docs/index.html b/docs/index.html
index 9c2f67c..dd23e86 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -677,6 +677,35 @@ window.addEventListener('resize', updateActiveNavLink);
 window.addEventListener('load', updateActiveNavLink);
 updateActiveNavLink();
 
+// On phones, skip the contact details and land directly at the enquiry form.
+function scrollToMobileContactForm() {
+  if (!mobileViewport.matches) return;
+  setMobileNav(false);
+  const form = document.querySelector('.contact-form');
+  const top = window.scrollY + form.getBoundingClientRect().top - siteNav.offsetHeight - 16;
+  window.scrollTo({
+    top,
+    behavior: window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 'instant' : 'smooth'
+  });
+}
+
+document.querySelectorAll('a[href="#contact"]').forEach((link) => {
+  link.addEventListener('click', (event) => {
+    if (!mobileViewport.matches || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) return;
+    event.preventDefault();
+    if (window.location.hash !== '#contact') history.pushState(null, '', '#contact');
+    scrollToMobileContactForm();
+  });
+});
+
+// Also handle contact links arriving from service and location pages.
+window.addEventListener('load', () => {
+  if (window.location.hash === '#contact') scrollToMobileContactForm();
+});
+window.addEventListener('hashchange', () => {
+  if (window.location.hash === '#contact') scrollToMobileContactForm();
+});
+
 const modal = document.getElementById('image-modal');
 const modalImage = document.getElementById('image-modal-img');
 const closeModalButton = modal.querySelector('.image-modal-close');