forked from tazuuu/CapitalMotors
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
96 lines (82 loc) · 3.26 KB
/
Copy pathscript.js
File metadata and controls
96 lines (82 loc) · 3.26 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const menuButton = document.getElementById("menu-button");
const siteNav = document.getElementById("site-nav");
const contactForm = document.getElementById("contact-form");
const header = document.querySelector(".site-header");
const hero = document.querySelector(".hero");
const revealTargets = document.querySelectorAll(
".section-intro, .section-heading, .about-copy, .image-pair, .feature-item, .stat-grid > div, .service-card, .location-copy, .map-frame, .review-card, .contact-info, .contact-form"
);
const setHeaderState = () => {
const scrollY = window.scrollY;
const heroHeight = hero ? hero.offsetHeight : 0;
header.classList.toggle("scrolled", scrollY > 24);
header.classList.toggle("transparent", scrollY > heroHeight);
};
setHeaderState();
window.addEventListener("scroll", setHeaderState, { passive: true });
menuButton.addEventListener("click", () => {
const isOpen = siteNav.classList.toggle("active");
menuButton.setAttribute("aria-expanded", String(isOpen));
menuButton.setAttribute("aria-label", isOpen ? "Close navigation" : "Open navigation");
document.body.classList.toggle("menu-open", isOpen);
});
siteNav.querySelectorAll("a").forEach((link) => {
link.addEventListener("click", () => {
siteNav.classList.remove("active");
menuButton.setAttribute("aria-expanded", "false");
menuButton.setAttribute("aria-label", "Open navigation");
document.body.classList.remove("menu-open");
});
});
if ("IntersectionObserver" in window) {
revealTargets.forEach((target, index) => {
target.classList.add("reveal");
target.style.transitionDelay = `${Math.min(index % 4, 3) * 70}ms`;
});
const revealObserver = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("is-visible");
revealObserver.unobserve(entry.target);
}
});
},
{ threshold: 0.16, rootMargin: "0px 0px -40px 0px" }
);
revealTargets.forEach((target) => revealObserver.observe(target));
} else {
revealTargets.forEach((target) => target.classList.add("is-visible"));
}
contactForm.addEventListener("submit", (event) => {
event.preventDefault();
const form = new FormData(contactForm);
const name = String(form.get("name") || "").trim();
const email = String(form.get("email") || "").trim();
const phone = String(form.get("phone") || "").trim();
const vehicle = String(form.get("vehicle") || "").trim();
const service = String(form.get("service") || "").trim();
const message = String(form.get("message") || "").trim();
if (!name || !email || !message) {
alert("Please fill all required fields: name, email, and message.");
return;
}
const subject = `New Service Request - ${name}`;
const body = [
`Customer Name: ${name}`,
`Email: ${email}`,
`Phone: ${phone || "Not provided"}`,
`Vehicle: ${vehicle || "Not specified"}`,
`Service Needed: ${service || "Not selected"}`,
"",
"Message:",
message,
].join("\n");
const gmailUrl =
"https://mail.google.com/mail/?view=cm&fs=1&to=capital.ktpm@gmail.com" +
`&su=${encodeURIComponent(subject)}` +
`&body=${encodeURIComponent(body)}`;
window.open(gmailUrl, "_blank");
alert("Opening email to send request.");
contactForm.reset();
});