customer-riverside/web/modules/custom/riverside_pt/js/scroll.js
Philip Peterson 797e580cc0 Create custom /contact page with details and appointment CTAs
- Refactor AboutController to PageController to handle multiple static pages:
  - /about
  - /services/{slug} (diagnostic, sports, pre-post, neuro)
  - /contact (new)

- New template riverside-pt-contact.html.twig:
  - Contact details (address, phone, email)
  - Office hours
  - 'Send us a message' section directing to booking tool
  - Multiple 'Make an Appointment' links back to /home#book-an-appointment

- Updated riverside_pt.routing.yml with riverside_pt.contact route
- Registered 'riverside_pt_contact' theme in riverside_pt.module
- Updated riverside_pt.install to skip legacy node creation for 'Contact' (and previously About/Services) to avoid alias conflicts
- Minor updates to home template, header handling, libraries (scroll support), and other controllers for consistency with page flows and email/booking features

All details pages (/about, /services/*, /contact) now include clear links back to 'Make an Appointment'.
2026-06-03 23:55:02 -07:00

38 lines
1.6 KiB
JavaScript

import zenscroll from "https://esm.sh/zenscroll@4.0.2";
var FIXED_BUFFER = 91; // breathing room below fixed header when menu is closed
var MOBILE_BUFFER = 0; // no offset needed when header is in-flow (scrolls away)
// Returns the effective scroll offset to clear the header.
// When the hamburger is open, offsetHeight already includes the expanded nav,
// so no extra buffer is needed. When closed, add FIXED_BUFFER for breathing room.
function headerOffset() {
var header = document.querySelector(".rpt-header");
if (!header) return MOBILE_BUFFER;
var pos = window.getComputedStyle(header).position;
if (pos !== "fixed" && pos !== "sticky") return MOBILE_BUFFER;
var nav = document.getElementById("rpt-main-nav");
var menuOpen = nav && nav.classList.contains("is-open");
return header.offsetHeight + (menuOpen ? 0 : FIXED_BUFFER);
}
// On load: if the URL has a hash (e.g. /home#pt-services from another page),
// re-scroll with the correct header offset instead of the browser's native jump.
document.addEventListener("DOMContentLoaded", function () {
if (!window.location.hash) return;
var target = document.querySelector(window.location.hash);
if (!target) return;
// Defer until layout is stable, then position correctly.
requestAnimationFrame(function () {
zenscroll.to(target, 0, headerOffset());
});
});
document.addEventListener("click", function (e) {
var link = e.target.closest("[data-scroll-to]");
if (!link) return;
var target = document.querySelector(link.dataset.scrollTo);
if (!target) return;
e.preventDefault();
zenscroll.to(target, 400, headerOffset());
});