-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
842 lines (716 loc) · 25.2 KB
/
Copy pathscript.js
File metadata and controls
842 lines (716 loc) · 25.2 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
function clarityCall(...args) {
window.clarity =
window.clarity ||
function () {
(window.clarity.q = window.clarity.q || []).push(arguments);
};
window.clarity(...args);
}
function getClarityVisitorId() {
const storageKey = "st_clarity_vid";
try {
let visitorId = sessionStorage.getItem(storageKey);
if (!visitorId) {
visitorId = `v_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
sessionStorage.setItem(storageKey, visitorId);
}
return visitorId;
} catch {
return `v_${Date.now().toString(36)}`;
}
}
function getClarityPageId() {
const path = window.location.pathname || "/";
const search = window.location.search || "";
return `${path}${search}` || "/";
}
function initMicrosoftClarity() {
if (window.__stClarityBootstrapped) return;
window.__stClarityBootstrapped = true;
const pageId = getClarityPageId();
clarityCall("identify", getClarityVisitorId(), undefined, pageId, document.title || pageId);
clarityCall("set", "page_path", pageId);
if (document.body && document.body.className) {
clarityCall("set", "page_type", document.body.className.trim());
}
}
function trackClarityEvent(eventName) {
if (!eventName) return;
clarityCall("event", eventName);
}
function trackClarityUpgrade(reason) {
if (!reason) return;
clarityCall("upgrade", reason);
}
const GA4_MEASUREMENT_ID = "G-N5V1084LC6";
function trackGa4Event(eventName, params) {
if (!eventName) return;
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ event: eventName, ...(params || {}) });
if (typeof gtag === "function") {
gtag("event", eventName, params || {});
}
}
function initConversionTracking() {
document.addEventListener(
"click",
(event) => {
const telLink = event.target.closest('a[href^="tel:"]');
if (telLink) {
trackClarityEvent("phone_click");
trackClarityUpgrade("phone_click");
trackGa4Event("phone_click", {
event_category: "conversion",
event_label: telLink.getAttribute("href") || "tel",
link_url: telLink.href,
page_path: getClarityPageId(),
});
return;
}
const smsLink = event.target.closest('a[href^="sms:"]');
if (smsLink) {
trackClarityEvent("sms_click");
trackClarityUpgrade("sms_click");
trackGa4Event("sms_click", {
event_category: "conversion",
event_label: smsLink.getAttribute("href") || "sms",
link_url: smsLink.href,
page_path: getClarityPageId(),
});
return;
}
const mailLink = event.target.closest('a[href^="mailto:"]');
if (mailLink) {
trackClarityEvent("email_click");
trackGa4Event("email_click", {
event_category: "engagement",
page_path: getClarityPageId(),
});
return;
}
const tracked = event.target.closest("[data-clarity-event]");
if (tracked && tracked.dataset.clarityEvent) {
trackClarityEvent(tracked.dataset.clarityEvent);
}
},
{ passive: true },
);
if (getClarityPageId().includes("thank-you")) {
trackGa4Event("contact_form_success", {
event_category: "conversion",
page_path: getClarityPageId(),
});
}
}
window.ScreenTeamClarity = {
init: initMicrosoftClarity,
identify(customId, customSessionId, customPageId, friendlyName) {
clarityCall("identify", customId, customSessionId, customPageId, friendlyName);
},
setTag(key, value) {
clarityCall("set", key, value);
},
event: trackClarityEvent,
upgrade: trackClarityUpgrade,
};
function initCurrentYear() {
document.querySelectorAll("#current-year").forEach((el) => {
el.textContent = new Date().getFullYear();
});
}
function initHeaderScroll() {
const header = document.querySelector(".site-header");
if (!header) return;
window.addEventListener(
"scroll",
() => header.classList.toggle("scrolled", window.scrollY > 40),
{ passive: true },
);
}
function initScrollReveal() {
const revealEls = document.querySelectorAll(
".reveal, .reveal-left, .reveal-right, .reveal-scale, .reveal-photo, .slide-enter, [data-reveal], .eyebrow:not(.hero-enter), .card-eyebrow:not(.hero-enter)",
);
if (!revealEls.length) return;
if ("IntersectionObserver" in window) {
const observer = new IntersectionObserver(
(entries, activeObserver) => {
entries.forEach((entry) => {
if (!entry.isIntersecting) return;
entry.target.classList.add("visible", "is-visible");
activeObserver.unobserve(entry.target);
});
},
{
threshold: 0.12,
rootMargin: "0px 0px -40px 0px",
},
);
revealEls.forEach((item) => observer.observe(item));
} else {
revealEls.forEach((item) => item.classList.add("visible", "is-visible"));
}
}
function initHeroPanels() {
document.querySelectorAll(".hero-panels").forEach((panels) => {
const hero = panels.closest(".hero");
if (!hero || hero.dataset.panelsInit) return;
hero.dataset.panelsInit = "1";
requestAnimationFrame(() => hero.classList.add("hero-panels-ready"));
});
}
function initHomeStripEntrance() {
if (!document.body.classList.contains("home-landing")) return;
const items = document.querySelectorAll(
".trust-strip .strip-slide, .st-intent-strip .strip-slide",
);
if (!items.length) return;
const reveal = () => {
items.forEach((item) => item.classList.add("is-visible"));
};
if (prefersReducedMotion()) {
reveal();
return;
}
const start = () => setTimeout(reveal, 1850);
const hero = document.querySelector(".hero");
if (hero?.classList.contains("hero-panels-ready")) {
start();
return;
}
if (!hero) {
start();
return;
}
const observer = new MutationObserver(() => {
if (!hero.classList.contains("hero-panels-ready")) return;
observer.disconnect();
start();
});
observer.observe(hero, { attributes: true, attributeFilter: ["class"] });
}
function prefersReducedMotion() {
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
}
function initHeroParallax() {
if (prefersReducedMotion()) return;
const hero = document.querySelector("body.home-landing .hero");
if (!hero) return;
const layers = hero.querySelectorAll(".hero-panels, .hero-cutout-wrap, .hero-overlay");
if (!layers.length) return;
let ticking = false;
function update() {
ticking = false;
const heroTop = hero.offsetTop;
const heroHeight = hero.offsetHeight;
const offset = Math.max(0, window.scrollY - heroTop);
const shift = Math.min(offset * 0.4, heroHeight);
layers.forEach((layer) => {
layer.style.setProperty("--st-hero-shift", `${Math.round(shift)}px`);
});
}
function queue() {
if (ticking) return;
ticking = true;
requestAnimationFrame(update);
}
update();
window.addEventListener("scroll", queue, { passive: true });
window.addEventListener("resize", queue, { passive: true });
}
function initParallaxBands() {
if (prefersReducedMotion()) return;
const backgrounds = document.querySelectorAll(".st-parallax-bg");
const contactBands = document.querySelectorAll(".contact-section--parallax");
if (!backgrounds.length && !contactBands.length) return;
let ticking = false;
function getOverscanPx(band) {
if (band.dataset.parallaxOverscan) {
return band.offsetHeight * Number(band.dataset.parallaxOverscan);
}
if (band.classList.contains("st-process-band")) {
return band.offsetHeight * 0.08;
}
if (band.classList.contains("st-route-band--parallax")) {
return band.offsetHeight * 0.28;
}
return band.offsetHeight * 0.3;
}
function clampShift(shift, maxShift) {
return Math.round(Math.max(-maxShift, Math.min(maxShift, shift)));
}
/** Scroll progress 0→1 as the band travels through the viewport */
function bandScrollProgress(band, vh) {
const rect = band.getBoundingClientRect();
const range = vh + band.offsetHeight;
const scrolled = Math.max(0, Math.min(range, vh - rect.top));
return scrolled / range;
}
function applySymmetricParallax(target, band, { intensity = 0.6, baseOffset = 0 } = {}) {
const vh = Math.max(window.innerHeight, 1);
const rect = band.getBoundingClientRect();
if (rect.bottom < 0 || rect.top > vh) return;
const maxShift = getOverscanPx(band);
const t = bandScrollProgress(band, vh);
const shift = clampShift((t - 0.5) * 2 * maxShift * intensity + baseOffset, maxShift);
target.style.setProperty("--st-band-shift", `${shift}px`);
}
function applyParallax(target, band) {
const vh = Math.max(window.innerHeight, 1);
const rect = band.getBoundingClientRect();
if (rect.bottom < 0 || rect.top > vh) return;
if (
band.classList.contains("work-teaser--parallax") ||
band.classList.contains("contact-section--parallax")
) {
applySymmetricParallax(target, band, { intensity: 0.55 });
return;
}
const maxShift = getOverscanPx(band);
let shift;
if (band.classList.contains("st-process-band")) {
shift = (rect.top - vh) * 0.35 + 56;
} else if (band.classList.contains("st-route-band--parallax")) {
shift = (rect.top - vh) * 0.28;
} else {
shift = (rect.top - vh) * 0.45;
}
target.style.setProperty("--st-band-shift", `${clampShift(shift, maxShift)}px`);
}
function update() {
ticking = false;
backgrounds.forEach((bg) => {
const band = bg.closest(
".work-teaser--parallax, .st-process-band, .st-route-band--parallax",
);
if (!band) return;
applyParallax(bg, band);
});
contactBands.forEach((band) => {
applyParallax(band, band);
});
}
function queue() {
if (ticking) return;
ticking = true;
requestAnimationFrame(update);
}
update();
window.addEventListener("scroll", queue, { passive: true });
window.addEventListener("resize", queue, { passive: true });
}
function initSiteNav() {
function closeAllDropdowns() {
document.querySelectorAll(".nav-dropdown-btn").forEach((btn) => {
btn.setAttribute("aria-expanded", "false");
});
}
document.querySelectorAll(".nav-dropdown-wrap").forEach((wrap) => {
const dropdownBtn = wrap.querySelector(".nav-dropdown-btn");
const dropdownMenu = wrap.querySelector(".nav-dropdown-menu");
if (!dropdownBtn || !dropdownMenu) return;
dropdownBtn.addEventListener("click", (e) => {
e.stopPropagation();
const expanded = dropdownBtn.getAttribute("aria-expanded") === "true";
closeAllDropdowns();
dropdownBtn.setAttribute("aria-expanded", String(!expanded));
});
dropdownMenu.addEventListener("click", (e) => e.stopPropagation());
});
document.addEventListener("click", closeAllDropdowns);
const hamburgerBtn = document.getElementById("hamburger-btn");
const mobileNav = document.getElementById("mobile-nav");
const navOverlay = document.getElementById("nav-overlay");
const mobileNavClose = document.getElementById("mobile-nav-close");
const mobileServToggle = document.getElementById("mobile-services-toggle");
const mobileServicesSub = document.getElementById("mobile-services-sub");
function openMobileNav() {
if (!mobileNav || !navOverlay || !hamburgerBtn) return;
mobileNav.classList.add("is-open");
navOverlay.classList.add("is-open");
hamburgerBtn.classList.add("is-open");
hamburgerBtn.setAttribute("aria-expanded", "true");
mobileNav.setAttribute("aria-hidden", "false");
mobileNav.removeAttribute("inert");
document.body.style.overflow = "hidden";
}
function closeMobileNav() {
if (!mobileNav || !navOverlay || !hamburgerBtn) return;
mobileNav.classList.remove("is-open");
navOverlay.classList.remove("is-open");
hamburgerBtn.classList.remove("is-open");
hamburgerBtn.setAttribute("aria-expanded", "false");
mobileNav.setAttribute("aria-hidden", "true");
mobileNav.setAttribute("inert", "");
document.body.style.overflow = "";
}
if (hamburgerBtn) {
hamburgerBtn.addEventListener("click", () => {
hamburgerBtn.classList.contains("is-open") ? closeMobileNav() : openMobileNav();
});
}
if (mobileNavClose) mobileNavClose.addEventListener("click", closeMobileNav);
if (navOverlay) navOverlay.addEventListener("click", closeMobileNav);
if (mobileNav) {
mobileNav.querySelectorAll("a").forEach((link) => {
link.addEventListener("click", closeMobileNav);
});
}
if (mobileServToggle && mobileServicesSub) {
mobileServToggle.addEventListener("click", () => {
const open = mobileServToggle.classList.toggle("is-open");
mobileServicesSub.classList.toggle("is-open", open);
mobileServToggle.setAttribute("aria-expanded", String(open));
});
}
const mobileAreasToggle = document.getElementById("mobile-areas-toggle");
const mobileAreasSub = document.getElementById("mobile-areas-sub");
if (mobileAreasToggle && mobileAreasSub) {
mobileAreasToggle.addEventListener("click", () => {
const open = mobileAreasToggle.classList.toggle("is-open");
mobileAreasSub.classList.toggle("is-open", open);
mobileAreasToggle.setAttribute("aria-expanded", String(open));
});
}
}
function initSiteChrome() {
initCurrentYear();
initHeaderScroll();
initSiteNav();
}
function initFormHandlers() {
const heroForm = document.getElementById("hero-contact-form");
const formSuccess = document.getElementById("form-success");
if (!heroForm || !formSuccess) return;
heroForm.addEventListener("submit", async function (e) {
e.preventDefault();
const submitBtn = heroForm.querySelector("[type='submit']");
const originalText = submitBtn.textContent;
submitBtn.disabled = true;
submitBtn.textContent = "Sending...";
try {
const res = await fetch(heroForm.action, {
method: "POST",
body: new FormData(heroForm),
headers: { Accept: "application/json" },
});
if (res.ok) {
trackClarityEvent("contact_form_submit");
trackClarityUpgrade("contact_form_submit");
trackGa4Event("contact_form_submit", {
event_category: "conversion",
form_id: heroForm.id || "contact-form",
page_path: getClarityPageId(),
});
submitBtn.textContent = "Sent! ✓";
setTimeout(() => {
heroForm.hidden = true;
formSuccess.hidden = false;
submitBtn.disabled = false;
submitBtn.textContent = originalText;
}, 1800);
} else {
submitBtn.disabled = false;
submitBtn.textContent = originalText;
alert("Something went wrong. Please call (727) 386-6562 directly.");
}
} catch {
submitBtn.disabled = false;
submitBtn.textContent = originalText;
alert("Could not send. Please call (727) 386-6562 directly.");
}
});
}
function initGalleryFilters() {
const galleryFilters = document.querySelectorAll(".gallery-filter");
const galleryItems = document.querySelectorAll(".gallery-item[data-category]");
if (!galleryFilters.length || !galleryItems.length) return;
const validFilters = new Set(Array.from(galleryFilters, (button) => button.dataset.filter));
function applyGalleryFilter(filter, updateUrl) {
const activeFilter = validFilters.has(filter) ? filter : "all";
galleryFilters.forEach((button) => {
const isActive = button.dataset.filter === activeFilter;
button.classList.toggle("active", isActive);
button.setAttribute("aria-selected", String(isActive));
});
galleryItems.forEach((item) => {
const isVisible = activeFilter === "all" || item.dataset.category === activeFilter;
item.hidden = !isVisible;
});
if (!updateUrl) return;
const currentUrl = new URL(window.location.href);
if (activeFilter === "all") {
currentUrl.searchParams.delete("filter");
} else {
currentUrl.searchParams.set("filter", activeFilter);
}
window.history.replaceState({}, "", currentUrl);
}
const initialFilter = new URLSearchParams(window.location.search).get("filter") || "all";
applyGalleryFilter(initialFilter, false);
galleryFilters.forEach((button) => {
button.addEventListener("click", () => {
applyGalleryFilter(button.dataset.filter, true);
});
});
}
function initFaqAccordion() {
document.querySelectorAll(".faq-question").forEach((btn) => {
btn.addEventListener("click", () => {
const expanded = btn.getAttribute("aria-expanded") === "true";
const answer = document.getElementById(btn.getAttribute("aria-controls"));
document.querySelectorAll(".faq-question").forEach((otherBtn) => {
const otherAnswer = document.getElementById(otherBtn.getAttribute("aria-controls"));
otherBtn.setAttribute("aria-expanded", "false");
if (otherAnswer) {
otherAnswer.setAttribute("aria-hidden", "true");
otherAnswer.setAttribute("inert", "");
}
});
btn.setAttribute("aria-expanded", String(!expanded));
if (answer) {
answer.setAttribute("aria-hidden", String(expanded));
if (expanded) {
answer.setAttribute("inert", "");
} else {
answer.removeAttribute("inert");
}
}
});
});
}
function initStGoogleReviews() {
const carousels = document.querySelectorAll("[data-st-review-carousel]");
if (!carousels.length) return;
carousels.forEach((carousel) => {
const track = carousel.querySelector(".st-review-carousel-track");
const prevBtn = carousel.querySelector(".st-review-carousel-btn.prev");
const nextBtn = carousel.querySelector(".st-review-carousel-btn.next");
const showcase = carousel.closest(".st-google-reviews-showcase");
const dotsContainer = showcase
? showcase.querySelector(".st-review-carousel-dots")
: null;
const summaryEl = document.getElementById("st-review-summary");
const starsEl = document.getElementById("st-review-stars");
const mapRatingEl = document.getElementById("st-map-rating");
const seedEl = showcase ? showcase.querySelector("#google-reviews-seed") : null;
if (!track || !prevBtn || !nextBtn || !dotsContainer || !showcase) return;
let cards = [];
let currentIndex = 0;
let reviews = [];
function escapeHtml(value) {
return String(value || "")
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
function getInitial(name) {
const clean = String(name || "").trim();
return clean ? clean.charAt(0).toUpperCase() : "?";
}
function formatStars(count) {
const stars = Math.max(1, Math.min(5, Number(count) || 5));
return "\u2605".repeat(stars);
}
function reviewCardMarkup(review) {
return (
'<article class="st-review-card">' +
'<div class="st-review-card-header">' +
'<span class="st-review-avatar" style="background:' +
escapeHtml(review.avatarColor || "#1a56c4") +
';" aria-hidden="true">' +
escapeHtml(getInitial(review.name)) +
"</span>" +
"<div>" +
'<div class="st-review-name">' +
escapeHtml(review.name) +
"</div>" +
'<div class="st-review-meta">' +
escapeHtml(review.meta || "") +
"</div>" +
"</div>" +
"</div>" +
'<div class="st-review-card-stars" role="img" aria-label="' +
escapeHtml(String(Number(review.stars) || 5)) +
' stars">' +
formatStars(review.stars) +
"</div>" +
'<p class="st-review-text">' +
escapeHtml(review.text || "") +
"</p>" +
'<div class="st-review-date">' +
escapeHtml(review.date || "") +
"</div>" +
"</article>"
);
}
function applySummary(payload) {
const rating = Number(payload.ratingValue || 5).toFixed(1);
const count = Number(payload.reviewCount || reviews.length || 0);
const label = count === 1 ? " review" : " reviews";
const summaryText = rating + " \u00b7 " + count + label;
if (summaryEl) summaryEl.textContent = summaryText;
if (starsEl) {
const stars = formatStars(payload.ratingValue || 5);
starsEl.textContent = stars;
starsEl.setAttribute(
"aria-label",
rating + " out of 5 stars",
);
}
if (mapRatingEl) {
mapRatingEl.textContent =
formatStars(payload.ratingValue || 5) +
" " +
rating +
" \u00b7 " +
count +
" Google review" +
(count === 1 ? "" : "s");
mapRatingEl.setAttribute(
"aria-label",
rating + " out of 5 stars, " + count + " Google reviews",
);
}
}
function visibleCount() {
if (window.innerWidth <= 720) return 1;
if (window.innerWidth <= 1060) return 2;
return 3;
}
function pageCount() {
return Math.max(1, Math.ceil(cards.length / visibleCount()));
}
function maxIndex() {
return Math.max(0, cards.length - visibleCount());
}
function cardSpan() {
if (!cards.length) return 0;
const styles = window.getComputedStyle(track);
const gap = parseFloat(styles.columnGap || styles.gap || "0");
return cards[0].getBoundingClientRect().width + gap;
}
function updateButtons() {
const singlePage = pageCount() <= 1 || cards.length === 0;
prevBtn.disabled = singlePage || currentIndex <= 0;
nextBtn.disabled = singlePage || currentIndex >= maxIndex();
}
function update() {
currentIndex = Math.max(0, Math.min(currentIndex, maxIndex()));
track.style.transform = "translateX(" + -currentIndex * cardSpan() + "px)";
const activePage = Math.floor(currentIndex / visibleCount());
dotsContainer.querySelectorAll(".st-review-carousel-dot").forEach((dot, index) => {
const isActive = index === activePage;
dot.classList.toggle("active", isActive);
if (isActive) {
dot.setAttribute("aria-current", "true");
} else {
dot.removeAttribute("aria-current");
}
});
updateButtons();
}
function buildDots() {
dotsContainer.innerHTML = "";
for (let index = 0; index < pageCount(); index += 1) {
const dot = document.createElement("button");
dot.type = "button";
dot.className = "st-review-carousel-dot" + (index === 0 ? " active" : "");
dot.setAttribute("aria-label", "Go to review page " + (index + 1));
if (index === 0) dot.setAttribute("aria-current", "true");
dot.addEventListener("click", () => {
currentIndex = index * visibleCount();
update();
});
dotsContainer.appendChild(dot);
}
}
function renderReviews(payload) {
reviews = Array.isArray(payload.reviews) ? payload.reviews.slice() : [];
applySummary(payload);
if (!reviews.length) {
track.innerHTML =
'<article class="st-review-card"><p class="st-review-text">Reviews will appear here once posted on Google.</p></article>';
} else {
track.innerHTML = reviews.map(reviewCardMarkup).join("");
}
cards = Array.from(track.querySelectorAll(".st-review-card"));
currentIndex = 0;
carousel.classList.toggle("single-review", cards.length <= 1);
buildDots();
update();
}
function parseSeedPayload() {
if (!seedEl) return null;
try {
return JSON.parse(seedEl.textContent || "{}");
} catch (error) {
console.warn("Google review seed parse failed:", error);
return null;
}
}
function reviewsFeedUrl() {
const script = document.querySelector('script[src*="script.js"]');
if (script && script.src) {
return new URL("data/google-reviews.json", script.src).href;
}
return new URL("data/google-reviews.json", window.location.href).href;
}
async function loadReviews() {
let payload = null;
try {
const response = await fetch(reviewsFeedUrl(), { cache: "no-store" });
if (response.ok) {
payload = await response.json();
}
} catch (error) {
console.warn("Google review feed fetch failed, using seed data:", error);
}
if (!payload) payload = parseSeedPayload();
if (!payload || !Array.isArray(payload.reviews)) {
payload = { ratingValue: 5, reviewCount: 0, reviews: [] };
}
renderReviews(payload);
}
prevBtn.addEventListener("click", () => {
currentIndex -= 1;
update();
});
nextBtn.addEventListener("click", () => {
currentIndex += 1;
update();
});
window.addEventListener("resize", () => {
buildDots();
update();
});
loadReviews();
});
}
function initPage() {
initMicrosoftClarity();
initConversionTracking();
initScrollReveal();
initHeroPanels();
initHomeStripEntrance();
initHeroParallax();
initParallaxBands();
initStGoogleReviews();
initFormHandlers();
initGalleryFilters();
initFaqAccordion();
if (
document.querySelector(".site-header") &&
!document.getElementById("site-header-include")
) {
initSiteChrome();
}
}
document.addEventListener("site:includes-loaded", initSiteChrome, { once: true });
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", initPage);
} else {
initPage();
}