-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
1683 lines (1458 loc) · 65.5 KB
/
Copy pathscript.js
File metadata and controls
1683 lines (1458 loc) · 65.5 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
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
document.documentElement.classList.add("is-enhanced");
const header = document.querySelector("[data-header]");
const navToggle = document.querySelector("[data-nav-toggle]");
const nav = document.querySelector("[data-nav]");
const navClose = document.querySelector("[data-nav-close]");
const serviceNav = document.querySelector("[data-service-nav]");
const WEB3FORMS_ACCESS_KEY = "4f7ab378-e677-4b67-b382-d548236a7160";
const GOOGLE_ANALYTICS_ID = "G-Z6M09GYPFY";
const whatsappThankYouUrl = "thank-you.html?source=whatsapp";
let analyticsLoaded = false;
const prefersReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const mobileNavBreakpoint = 1080;
const navBackdrop = nav
? Object.assign(document.createElement("button"), {
type: "button",
className: "mobile-nav-backdrop"
})
: null;
if (navBackdrop) {
navBackdrop.setAttribute("aria-label", "Close menu");
navBackdrop.setAttribute("aria-hidden", "true");
document.body.append(navBackdrop);
}
const loader = document.createElement("div");
loader.className = "site-loader";
loader.setAttribute("aria-hidden", "true");
loader.innerHTML = "<span></span>";
document.body.prepend(loader);
window.addEventListener("load", () => {
document.documentElement.classList.add("is-ready");
window.setTimeout(() => loader.remove(), prefersReducedMotion ? 40 : 650);
});
const scrollProgress = document.createElement("div");
scrollProgress.className = "scroll-progress";
scrollProgress.setAttribute("aria-hidden", "true");
scrollProgress.innerHTML = "<span></span>";
document.body.prepend(scrollProgress);
const updateScrollProgress = () => {
const max = document.documentElement.scrollHeight - window.innerHeight;
const percent = max > 0 ? Math.min(100, Math.max(0, (window.scrollY / max) * 100)) : 0;
scrollProgress.style.setProperty("--scroll-progress", `${percent}%`);
};
updateScrollProgress();
window.addEventListener("scroll", updateScrollProgress, { passive: true });
const loadAnalytics = () => {
if (analyticsLoaded || !GOOGLE_ANALYTICS_ID || !/^https?:$/.test(window.location.protocol)) return;
analyticsLoaded = true;
window[`ga-disable-${GOOGLE_ANALYTICS_ID}`] = false;
window.dataLayer = window.dataLayer || [];
window.gtag = window.gtag || function gtag() {
window.dataLayer.push(arguments);
};
const tag = document.createElement("script");
tag.async = true;
tag.src = `https://www.googletagmanager.com/gtag/js?id=${encodeURIComponent(GOOGLE_ANALYTICS_ID)}`;
document.head.append(tag);
window.gtag("js", new Date());
window.gtag("config", GOOGLE_ANALYTICS_ID, {
anonymize_ip: true,
send_page_view: true
});
};
const disableAnalytics = () => {
if (!GOOGLE_ANALYTICS_ID) return;
window[`ga-disable-${GOOGLE_ANALYTICS_ID}`] = true;
};
const trackConversion = (eventName, params = {}) => {
if (typeof window.gtag !== "function") return;
window.gtag("event", eventName, {
website_area: document.title,
...params
});
};
const currentPage = window.location.pathname.split("/").pop() || "index.html";
const pageBookingDefaults = {
"index.html": "Not sure yet",
"services.html": "Not sure yet",
"contact.html": "Not sure yet",
"pricing.html": "Not sure yet",
"estimator.html": "Not sure yet",
"areas.html": "Not sure yet",
"availability.html": "Not sure yet",
"about.html": "Not sure yet",
"gallery.html": "Not sure yet",
"reviews.html": "Not sure yet",
"recent-jobs.html": "Not sure yet",
"refer-a-friend.html": "Not sure yet",
"faq.html": "Not sure yet",
"car-services-feltham.html": "Oil and filter service",
"car-services-bedfont.html": "Oil and filter service",
"car-services-ashford.html": "Oil and filter service",
"car-services-sunbury.html": "Oil and filter service",
"car-services-hounslow.html": "Oil and filter service",
"car-services-kingston.html": "Oil and filter service",
"scratch-bumper-repairs.html": "Bumper scratches or bumper replacement",
"bumper-repair-feltham.html": "Bumper scratches or bumper replacement",
"single-panel-repair-respray.html": "Single panel repair and re-spray",
"single-panel-respray-feltham.html": "Single panel repair and re-spray",
"obd-diagnostics.html": "OBD diagnostics and fault code scan",
"mobile-obd-diagnostics-feltham.html": "OBD diagnostics and fault code scan",
"bmw-mini-coding.html": "BMW and MINI coding",
"bmw-mini-coding-feltham.html": "BMW and MINI coding",
"trim-fitment.html": "Screen, cluster or trim upgrade",
"mot-support.html": "Not sure yet",
"ecu-remapping.html": "Not sure yet"
};
const BUSINESS_HOURS_SUMMARY = "Standard hours are Monday to Wednesday 10am to 6pm and Saturday to Sunday 10am to 6pm. Thursday and Friday are closed.";
const OUT_OF_HOURS_SUMMARY = "Weekend evening appointments run on Saturday and Sunday from 6pm to 11.30pm and add a £50 evening booking fee.";
const BOOKING_SLOT_OPTIONS = [
{ key: "mon-wed-day", label: "Monday to Wednesday daytime (10am to 6pm)", fee: 0 },
{ key: "saturday-day", label: "Saturday daytime (10am to 6pm)", fee: 0 },
{ key: "sunday-day", label: "Sunday daytime (10am to 6pm)", fee: 0 },
{ key: "saturday-ooh", label: "Saturday evening appointment (6pm to 11.30pm, +£50 evening booking fee)", fee: 50 },
{ key: "sunday-ooh", label: "Sunday evening appointment (6pm to 11.30pm, +£50 evening booking fee)", fee: 50 }
];
const BOOKING_SLOT_LOOKUP = Object.fromEntries(BOOKING_SLOT_OPTIONS.map((option) => [option.key, option]));
const BOOKING_SLOT_LABELS = Object.fromEntries(BOOKING_SLOT_OPTIONS.map((option) => [option.key, option.label]));
const LONDON_WEEKDAY_MAP = {
Mon: "mon",
Tue: "tue",
Wed: "wed",
Thu: "thu",
Fri: "fri",
Sat: "sat",
Sun: "sun"
};
const getLondonNow = () => {
const parts = new Intl.DateTimeFormat("en-GB", {
timeZone: "Europe/London",
weekday: "short",
hour: "2-digit",
minute: "2-digit",
hourCycle: "h23"
}).formatToParts(new Date());
const values = Object.fromEntries(
parts
.filter(({ type }) => type !== "literal")
.map(({ type, value }) => [type, value])
);
const dayKey = LONDON_WEEKDAY_MAP[values.weekday] || "mon";
const hour = Number(values.hour || 0);
const minute = Number(values.minute || 0);
return {
dayKey,
hour,
minute,
totalMinutes: (hour * 60) + minute
};
};
const getBookingSlotKey = (value) => {
const normalized = String(value || "").trim();
if (!normalized) return null;
if (BOOKING_SLOT_LOOKUP[normalized]) return normalized;
const exactLabel = BOOKING_SLOT_OPTIONS.find((option) => option.label === normalized);
if (exactLabel) return exactLabel.key;
const compact = normalized.replace(/\s+/g, " ").toLowerCase();
const textMatch = BOOKING_SLOT_OPTIONS.find((option) => {
const optionLabel = option.label.toLowerCase();
return compact === optionLabel || compact.includes(optionLabel) || optionLabel.includes(compact);
});
return textMatch?.key || null;
};
const getBookingSlotLabel = (value) => {
const slotKey = getBookingSlotKey(value);
return slotKey ? BOOKING_SLOT_LOOKUP[slotKey].label : String(value || "Availability request");
};
const isOutOfHoursKey = (slotKey) => (BOOKING_SLOT_LOOKUP[slotKey]?.fee || 0) > 0;
const getSlotOptionForKey = (select, slotKey) => [...select.options].find((option) => (
getBookingSlotKey(option.value || option.textContent) === slotKey
));
const setBookingSelectValue = (select, slotValueOrKey) => {
const slotKey = getBookingSlotKey(slotValueOrKey);
if (!slotKey) return false;
const option = getSlotOptionForKey(select, slotKey);
if (!option) return false;
select.value = option.value;
return true;
};
const getBusinessHoursState = (now = getLondonNow()) => {
const { dayKey, totalMinutes } = now;
let liveKey = null;
let recommendedKey = "mon-wed-day";
let statusTone = "closed";
let statusText = "Currently closed.";
if (["mon", "tue"].includes(dayKey)) {
recommendedKey = "mon-wed-day";
if (totalMinutes < 600) {
statusText = "Currently closed. Monday to Wednesday daytime bookings start at 10am.";
} else if (totalMinutes < 1080) {
liveKey = "mon-wed-day";
statusTone = "open";
statusText = "Open now for Monday to Wednesday daytime bookings (10am to 6pm).";
} else {
statusText = dayKey === "mon"
? "Currently closed. The next Monday to Wednesday daytime slot starts on Tuesday at 10am."
: "Currently closed. The next Monday to Wednesday daytime slot starts on Wednesday at 10am.";
}
} else if (dayKey === "wed") {
if (totalMinutes < 600) {
recommendedKey = "mon-wed-day";
statusText = "Currently closed. Wednesday daytime bookings start at 10am.";
} else if (totalMinutes < 1080) {
liveKey = "mon-wed-day";
recommendedKey = "mon-wed-day";
statusTone = "open";
statusText = "Open now for Monday to Wednesday daytime bookings (10am to 6pm).";
} else {
recommendedKey = "saturday-day";
statusText = "Currently closed. Thursday and Friday are closed, so the next standard slot starts on Saturday at 10am.";
}
} else if (dayKey === "thu" || dayKey === "fri") {
recommendedKey = "saturday-day";
statusText = "Currently closed. Thursday and Friday are closed. The next standard slot is Saturday daytime from 10am to 6pm.";
} else if (dayKey === "sat") {
if (totalMinutes < 600) {
recommendedKey = "saturday-day";
statusText = "Currently closed. Saturday daytime bookings start at 10am.";
} else if (totalMinutes < 1080) {
liveKey = "saturday-day";
recommendedKey = "saturday-day";
statusTone = "open";
statusText = "Open now for Saturday daytime bookings (10am to 6pm).";
} else if (totalMinutes < 1410) {
liveKey = "saturday-ooh";
recommendedKey = "saturday-ooh";
statusTone = "out-of-hours";
statusText = "Open now for Saturday evening appointment requests (6pm to 11.30pm). A £50 evening booking fee applies.";
} else {
recommendedKey = "sunday-day";
statusText = "Currently closed. The next standard slot is Sunday daytime from 10am to 6pm.";
}
} else if (dayKey === "sun") {
if (totalMinutes < 600) {
recommendedKey = "sunday-day";
statusText = "Currently closed. Sunday daytime bookings start at 10am.";
} else if (totalMinutes < 1080) {
liveKey = "sunday-day";
recommendedKey = "sunday-day";
statusTone = "open";
statusText = "Open now for Sunday daytime bookings (10am to 6pm).";
} else if (totalMinutes < 1410) {
liveKey = "sunday-ooh";
recommendedKey = "sunday-ooh";
statusTone = "out-of-hours";
statusText = "Open now for Sunday evening appointment requests (6pm to 11.30pm). A £50 evening booking fee applies.";
} else {
recommendedKey = "mon-wed-day";
statusText = "Currently closed. Monday to Wednesday daytime bookings resume at 10am.";
}
}
return {
liveKey,
recommendedKey,
recommendedLabel: BOOKING_SLOT_LOOKUP[recommendedKey].label,
statusTone,
statusText,
formText: `${statusText} ${BUSINESS_HOURS_SUMMARY} ${OUT_OF_HOURS_SUMMARY} Recommended request window: ${BOOKING_SLOT_LOOKUP[recommendedKey].label}.`
};
};
const setHeaderState = () => {
header?.classList.toggle("is-scrolled", window.scrollY > 12);
};
setHeaderState();
window.addEventListener("scroll", setHeaderState, { passive: true });
const markCurrentNavigation = (navigation) => {
navigation?.querySelectorAll("a[href]").forEach((link) => {
const href = link.getAttribute("href") || "";
const page = href.split("#")[0] || "index.html";
const homeMatch = currentPage === "index.html" && (href === "#top" || page === "index.html");
if (homeMatch || page === currentPage) {
link.classList.add("is-current");
link.setAttribute("aria-current", "page");
}
});
};
markCurrentNavigation(nav);
markCurrentNavigation(serviceNav);
const setNavOpen = (isOpen, { restoreFocus = false } = {}) => {
nav?.classList.toggle("is-open", isOpen);
document.body.classList.toggle("has-nav-open", isOpen);
navBackdrop?.classList.toggle("is-visible", isOpen);
navToggle?.setAttribute("aria-expanded", String(isOpen));
navToggle?.setAttribute("aria-label", isOpen ? "Close menu" : "Open menu");
if (!isOpen && restoreFocus) navToggle?.focus();
if (isOpen) navClose?.focus();
};
const closeNav = (options) => {
setNavOpen(false, options);
};
navToggle?.addEventListener("click", () => {
const isOpen = !nav?.classList.contains("is-open");
setNavOpen(Boolean(isOpen));
});
navClose?.addEventListener("click", () => {
closeNav({ restoreFocus: true });
});
navBackdrop?.addEventListener("click", () => {
closeNav({ restoreFocus: true });
});
nav?.addEventListener("click", (event) => {
const link = event.target instanceof Element ? event.target.closest("a[href]") : null;
if (link && nav.contains(link)) {
closeNav();
}
});
document.addEventListener("keydown", (event) => {
if (event.key === "Escape") {
closeNav({ restoreFocus: true });
}
});
window.addEventListener("resize", () => {
if (window.innerWidth > mobileNavBreakpoint && nav?.classList.contains("is-open")) {
closeNav();
}
});
const bookingModal = document.createElement("div");
bookingModal.className = "booking-modal";
bookingModal.setAttribute("data-booking-modal", "");
bookingModal.setAttribute("aria-hidden", "true");
bookingModal.innerHTML = `
<div class="booking-modal__dialog" role="dialog" aria-modal="true" aria-labelledby="booking-modal-title" aria-describedby="booking-modal-copy" tabindex="-1">
<button class="booking-modal__close" type="button" aria-label="Close booking form" data-booking-modal-close>
<span aria-hidden="true"></span>
</button>
<div class="booking-modal__layout">
<aside class="booking-modal__side">
<span class="booking-modal__eyebrow">Quick booking</span>
<h2 id="booking-modal-title">Send a booking enquiry from this page</h2>
<p id="booking-modal-copy">Send the booking details directly from the menu. Use email for a tracked enquiry or WhatsApp when you want to attach photos straight away.</p>
<ul class="booking-modal__list">
<li>Monday to Wednesday daytime plus weekend booking requests</li>
<li>Thursday and Friday are closed</li>
<li>Service, vehicle and area details in one step</li>
<li>Saturday and Sunday evening appointments after 6pm include a £50 evening booking fee</li>
</ul>
<div class="booking-modal__actions">
<a class="btn btn-secondary" href="tel:+447347388893">Call 07347 388893</a>
<a class="btn btn-secondary" href="https://wa.me/447347388893" target="_blank" rel="noopener">WhatsApp directly</a>
</div>
</aside>
<form class="booking-form booking-modal__form" action="https://api.web3forms.com/submit" method="POST" data-booking-form data-lead-form>
<input type="hidden" name="access_key" value="${WEB3FORMS_ACCESS_KEY}">
<input type="hidden" name="subject" value="New Tuned Performance quick booking enquiry">
<input type="hidden" name="from_name" value="Tuned Performance Website">
<input type="hidden" name="redirect" value="https://tunedperformance.co.uk/thank-you.html?source=email">
<input type="hidden" name="lead_source" value="Menu booking modal">
<input type="hidden" name="page_context" value="${document.title}">
<input class="botcheck" aria-label="Leave this field empty" type="checkbox" name="botcheck" tabindex="-1" autocomplete="off">
<div class="form-row">
<label for="modal-book-name">Name</label>
<input id="modal-book-name" name="name" type="text" autocomplete="name" required>
</div>
<div class="form-row">
<label for="modal-book-phone">Phone</label>
<input id="modal-book-phone" name="phone" type="tel" autocomplete="tel" required>
</div>
<div class="form-row">
<label for="modal-book-email">Email</label>
<input id="modal-book-email" name="email" type="email" autocomplete="email" placeholder="For email replies">
</div>
<div class="form-row">
<label for="modal-book-postcode">Postcode or area</label>
<input id="modal-book-postcode" name="postcode" type="text" autocomplete="postal-code" required>
</div>
<div class="form-row">
<label for="modal-book-vehicle">Vehicle</label>
<input id="modal-book-vehicle" name="vehicle" type="text" placeholder="Make, model, year or registration">
</div>
<div class="form-row">
<label for="modal-book-service">Service needed</label>
<select id="modal-book-service" name="service">
<option>Oil and filter service</option>
<option>Spark plugs and ignition coils</option>
<option>Brakes, pads and discs</option>
<option>Tyres and wheel replacement</option>
<option>Bumper scratches or bumper replacement</option>
<option>Single panel repair and re-spray</option>
<option>BMW and MINI coding</option>
<option>Screen, cluster or trim upgrade</option>
<option>OBD diagnostics and fault code scan</option>
<option>Not sure yet</option>
</select>
</div>
<div class="form-row">
<label for="modal-book-slot">Preferred availability</label>
<select id="modal-book-slot" name="slot">
<option>Monday to Wednesday daytime (10am to 6pm)</option>
<option>Saturday daytime (10am to 6pm)</option>
<option>Sunday daytime (10am to 6pm)</option>
<option>Saturday evening appointment (6pm to 11.30pm, +£50 evening booking fee)</option>
<option>Sunday evening appointment (6pm to 11.30pm, +£50 evening booking fee)</option>
</select>
</div>
<div class="form-row form-row-full">
<label for="modal-book-message">What is happening?</label>
<textarea id="modal-book-message" name="message" rows="4" placeholder="Add the oil service, plugs, brakes, wheel change, bumper damage, parts to fit, screen upgrade or coding features needed."></textarea>
</div>
<div class="form-actions form-row-full">
<button class="btn btn-primary" type="submit">Send email enquiry</button>
<button class="btn btn-secondary btn-on-light" type="button" data-whatsapp-submit>Send on WhatsApp</button>
</div>
<p class="form-note">Email enquiries go through Web3Forms. Use this route for planned servicing, cosmetic work, coding and upgrade bookings.</p>
<p class="form-status" data-form-status role="status" aria-live="polite"></p>
</form>
</div>
</div>
`;
document.body.append(bookingModal);
const bookingModalDialog = bookingModal.querySelector(".booking-modal__dialog");
const bookingModalClose = bookingModal.querySelector("[data-booking-modal-close]");
const bookingModalForm = bookingModal.querySelector("[data-booking-form]");
const bookingModalService = bookingModal.querySelector('select[name="service"]');
const bookingModalLeadSource = bookingModal.querySelector('input[name="lead_source"]');
const bookingModalPageContext = bookingModal.querySelector('input[name="page_context"]');
const bookingModalTriggers = [...new Set(document.querySelectorAll(
".nav-book-link, a.btn[href='contact.html'], .mobile-bar a[href='contact.html'], .route-item[href='contact.html']"
))];
let bookingModalRestoreFocus = null;
const estimates = {
oil: { small: "From £50", medium: "£60-£80 guide", large: "Vehicle and parts review needed" },
plugs: { small: "From £50", medium: "£60-£90 guide", large: "Vehicle and parts review needed" },
brakes: { small: "From £60", medium: "£90-£160 guide", large: "Vehicle and parts review needed" },
wheels: { small: "From £25", medium: "£35-£60 guide", large: "Vehicle and parts review needed" },
bumper: { small: "From £60", medium: "£90-£160 guide", large: "Photo quote needed" },
panel: { small: "From £100", medium: "£150-£240 guide", large: "Panel review needed" },
scan: { small: "From £50", medium: "£50-£90 guide", large: "Vehicle symptoms review needed" },
upgrades: { small: "From £30", medium: "£50-£90 guide", large: "Parts review needed" },
coding: { small: "From £40", medium: "£60-£90 guide", large: "Compatibility check needed" },
};
const estimator = document.querySelector("[data-estimator]");
const estimateService = document.querySelector("[data-estimate-service]");
const estimateSize = document.querySelector("[data-estimate-size]");
const estimateResult = document.querySelector("[data-estimate-result]");
const updateEstimate = () => {
if (!estimateService || !estimateSize || !estimateResult) return;
const service = estimateService.value;
const size = estimateSize.value;
estimateResult.innerHTML = estimates[service]?.[size] || "Quote needed";
estimateResult.classList.remove("is-updated");
void estimateResult.offsetWidth;
estimateResult.classList.add("is-updated");
trackConversion("quick_estimate_change", { service, size });
};
estimator?.addEventListener("change", updateEstimate);
updateEstimate();
const remapRanges = {
"turbo-diesel": {
text: "Typical enquiry range: 20-35 bhp and stronger mid-range torque.",
angle: "-18deg"
},
"turbo-petrol": {
text: "Typical enquiry range: 25-45 bhp with sharper throttle response.",
angle: "8deg"
},
"naturally-aspirated": {
text: "Typical gains are usually modest. Enquire for vehicle-specific advice.",
angle: "-44deg"
}
};
const setBookingModalDefaultService = () => {
if (!(bookingModalService instanceof HTMLSelectElement)) return;
bookingModalService.value = pageBookingDefaults[currentPage] || "Not sure yet";
};
const getBookingTriggerSource = (trigger) => {
if (!(trigger instanceof HTMLElement)) {
return "Quick booking modal";
}
if (trigger.classList.contains("nav-book-link")) {
return "Header book";
}
if (trigger.closest(".mobile-bar")) {
return "Mobile quote bar";
}
if (trigger.classList.contains("route-item")) {
return "Quick route quote";
}
if (trigger.closest(".hero-actions")) {
return "Hero quote CTA";
}
if (trigger.closest(".conversion-strip")) {
return "Conversion strip CTA";
}
if (trigger.closest(".quote-ready")) {
return "Quote section CTA";
}
if (trigger.closest(".mini-cta")) {
return "Mini CTA";
}
if (trigger.classList.contains("btn")) {
return "Page quote button";
}
return "Quick booking modal";
};
const closeBookingModal = ({ restoreFocus = true } = {}) => {
bookingModal.classList.remove("is-visible");
bookingModal.setAttribute("aria-hidden", "true");
document.body.classList.remove("has-modal");
if (restoreFocus && bookingModalRestoreFocus instanceof HTMLElement) {
bookingModalRestoreFocus.focus();
}
};
const openBookingModal = (trigger = null) => {
bookingModalRestoreFocus = trigger instanceof HTMLElement ? trigger : document.activeElement;
if (bookingModalLeadSource instanceof HTMLInputElement) {
bookingModalLeadSource.value = `${getBookingTriggerSource(trigger)} - ${currentPage}`;
}
if (bookingModalPageContext instanceof HTMLInputElement) {
bookingModalPageContext.value = document.title;
}
setBookingModalDefaultService();
bookingModal.classList.add("is-visible");
bookingModal.setAttribute("aria-hidden", "false");
document.body.classList.add("has-modal");
bookingModalDialog?.focus();
const firstField = bookingModal.querySelector("input:not([type='hidden']):not(.botcheck), select, textarea");
if (firstField instanceof HTMLElement) {
window.setTimeout(() => firstField.focus(), 40);
}
trackConversion("booking_modal_open", { page: currentPage });
};
bookingModalTriggers.forEach((trigger) => {
trigger.setAttribute("aria-haspopup", "dialog");
trigger.setAttribute("aria-controls", "site-booking-modal");
trigger.addEventListener("click", (event) => {
event.preventDefault();
closeNav();
openBookingModal(trigger);
});
});
bookingModal.id = "site-booking-modal";
bookingModal.addEventListener("click", (event) => {
if (event.target === bookingModal) {
closeBookingModal();
}
});
bookingModalClose?.addEventListener("click", () => {
closeBookingModal();
});
document.addEventListener("keydown", (event) => {
if (!bookingModal.classList.contains("is-visible")) return;
if (event.key === "Escape") {
closeBookingModal();
return;
}
if (event.key !== "Tab") return;
const focusable = [...bookingModal.querySelectorAll(
'a[href], button:not([disabled]), textarea:not([disabled]), input:not([type="hidden"]):not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])'
)].filter((element) => element instanceof HTMLElement && element.offsetParent !== null);
if (!focusable.length) return;
const first = focusable[0];
const last = focusable[focusable.length - 1];
if (event.shiftKey && document.activeElement === first) {
event.preventDefault();
last.focus();
} else if (!event.shiftKey && document.activeElement === last) {
event.preventDefault();
first.focus();
}
});
const ensureHiddenFormField = (form, fieldName) => {
let field = form.querySelector(`input[name="${fieldName}"]`);
if (field instanceof HTMLInputElement) return field;
field = document.createElement("input");
field.type = "hidden";
field.name = fieldName;
const botcheck = form.querySelector(".botcheck");
if (botcheck) {
botcheck.insertAdjacentElement("beforebegin", field);
} else {
form.prepend(field);
}
return field;
};
const ensureBusinessHoursNote = (form) => {
let note = form.querySelector("[data-business-hours-note]");
if (note instanceof HTMLElement) return note;
note = document.createElement("p");
note.className = "form-hours-note";
note.dataset.businessHoursNote = "";
note.setAttribute("role", "status");
note.setAttribute("aria-live", "polite");
const bookingSlotRow = form.querySelector('select[name="slot"]')?.closest(".form-row");
if (bookingSlotRow instanceof HTMLElement) {
note.classList.add("form-row-full");
bookingSlotRow.insertAdjacentElement("afterend", note);
return note;
}
const estimatorGrid = form.querySelector("[data-full-slot]")?.closest(".estimator-field-grid");
if (estimatorGrid instanceof HTMLElement) {
note.classList.add("estimator-wide-field");
estimatorGrid.append(note);
return note;
}
const formNote = form.querySelector(".form-note");
if (formNote instanceof HTMLElement) {
formNote.insertAdjacentElement("beforebegin", note);
return note;
}
form.append(note);
return note;
};
const syncBusinessHourForms = () => {
const businessState = getBusinessHoursState();
document.querySelectorAll("[data-booking-form], [data-estimate-email-form]").forEach((form) => {
const slotSelect = form.querySelector('select[name="slot"], [data-full-slot]');
if (!(slotSelect instanceof HTMLSelectElement)) return;
if (slotSelect.dataset.userSelected !== "true") {
setBookingSelectValue(slotSelect, businessState.recommendedKey);
}
const selectedKey = getBookingSlotKey(slotSelect.value || slotSelect.selectedOptions[0]?.textContent);
const selectedLabel = selectedKey
? BOOKING_SLOT_LOOKUP[selectedKey].label
: (slotSelect.selectedOptions[0]?.textContent?.trim() || slotSelect.value || "Availability request");
const selectedFee = BOOKING_SLOT_LOOKUP[selectedKey]?.fee || 0;
const note = ensureBusinessHoursNote(form);
note.classList.remove("is-open", "is-out-of-hours", "is-closed");
note.classList.add(
businessState.statusTone === "out-of-hours"
? "is-out-of-hours"
: businessState.statusTone === "open"
? "is-open"
: "is-closed"
);
note.textContent = `${businessState.formText} The form uses current UK time and updates automatically. Selected slot: ${selectedLabel}. ${selectedFee ? "This slot includes the £50 evening booking fee." : "This slot is within standard hours."}`;
ensureHiddenFormField(form, "business_hours_status").value = businessState.statusText;
ensureHiddenFormField(form, "business_hours_summary").value = `${BUSINESS_HOURS_SUMMARY} ${OUT_OF_HOURS_SUMMARY}`;
ensureHiddenFormField(form, "recommended_booking_window").value = businessState.recommendedLabel;
ensureHiddenFormField(form, "selected_booking_window").value = selectedLabel;
ensureHiddenFormField(form, "out_of_hours_fee").value = selectedFee ? "£50 applies" : "Not applied";
});
return businessState;
};
document.querySelectorAll('[data-booking-form] select[name="slot"], [data-estimate-email-form] [data-full-slot]').forEach((select) => {
select.addEventListener("change", () => {
select.dataset.userSelected = "true";
syncBusinessHourForms();
updateFullEstimator?.();
});
});
const availability = document.querySelector("[data-availability]");
const availabilityNote = document.querySelector("[data-availability-note]");
const availabilityLabels = BOOKING_SLOT_LABELS;
availability?.addEventListener("click", (event) => {
const target = event.target instanceof Element ? event.target : null;
const card = target?.closest("[data-slot]");
if (!(card instanceof HTMLElement)) return;
availability.querySelectorAll("[data-slot]").forEach((item) => {
item.classList.toggle("is-active", item === card);
});
const label = availabilityLabels[card.dataset.slot] || "Availability request";
if (availabilityNote) availabilityNote.textContent = `Selected booking window: ${label}`;
document.querySelectorAll('[data-booking-form] select[name="slot"], [data-estimate-email-form] [data-full-slot], [data-slot-field]').forEach((field) => {
if (!(field instanceof HTMLSelectElement)) return;
setBookingSelectValue(field, card.dataset.slot || label);
field.dataset.userSelected = "true";
});
syncBusinessHourForms();
updateFullEstimator?.();
if (availabilityNote) {
availabilityNote.classList.remove("is-updated");
void availabilityNote.offsetWidth;
availabilityNote.classList.add("is-updated");
}
trackConversion("availability_select", { slot: label });
});
const codingPreview = document.querySelector("[data-coding-preview]");
const codingResult = document.querySelector("[data-coding-result]");
const codingLabels = {
comfort: "Selected coding route: Comfort coding. Send the vehicle, model year and the exact convenience features wanted.",
lighting: "Selected coding route: Lighting coding. Send the current light behaviour and the setting you want changed.",
display: "Selected coding route: Display and iDrive coding. Send photos of the current menu or cluster if possible.",
compatibility: "Selected coding route: Compatibility review. Send the registration or model/year plus your full feature wish list."
};
codingPreview?.addEventListener("click", (event) => {
const target = event.target instanceof Element ? event.target : null;
const card = target?.closest("[data-coding-option]");
if (!(card instanceof HTMLElement)) return;
codingPreview.querySelectorAll("[data-coding-option]").forEach((item) => {
item.classList.toggle("is-active", item === card);
});
const label = codingLabels[card.dataset.codingOption] || codingLabels.compatibility;
if (codingResult) {
codingResult.textContent = label;
codingResult.classList.remove("is-updated");
void codingResult.offsetWidth;
codingResult.classList.add("is-updated");
}
trackConversion("coding_option_select", { option: card.dataset.codingOption || "compatibility" });
});
const coreAreas = ["feltham", "bedfont", "ashford", "sunbury", "hounslow", "kingston"];
const areaFilter = document.querySelector("[data-area-filter]");
const areaMessage = document.querySelector("[data-area-message]");
areaFilter?.addEventListener("input", () => {
const value = areaFilter.value.trim().toLowerCase();
if (!areaMessage) return;
if (!value) {
areaMessage.textContent = "Start typing to check the core coverage list.";
return;
}
const match = coreAreas.find((area) => area.includes(value) || value.includes(area));
areaMessage.textContent = match
? `${match[0].toUpperCase()}${match.slice(1)} is in the core mobile coverage list.`
: "That area may still be possible. Send the postcode for confirmation.";
areaMessage.classList.toggle("is-positive", Boolean(match));
});
const getFormStatus = (form) => form.querySelector("[data-form-status]") || form.closest(".full-estimator")?.querySelector("[data-form-status]");
const validateEmailFormSetup = (form, event) => {
const accessKey = form.querySelector('input[name="access_key"]')?.value.trim();
const status = getFormStatus(form);
if (!accessKey || accessKey !== WEB3FORMS_ACCESS_KEY) {
event.preventDefault();
if (status) status.textContent = "Email sending is not connected yet. Please use WhatsApp or call instead.";
return false;
}
if (status) status.textContent = "Sending your enquiry securely...";
trackConversion("generate_lead", { method: "email_form" });
return true;
};
const openWhatsAppLead = (url) => {
trackConversion("generate_lead", { method: "whatsapp" });
trackConversion("whatsapp_click", { link_url: url });
const opened = window.open(url, "_blank", "noopener");
if (!opened) {
window.location.href = url;
return;
}
window.setTimeout(() => {
window.location.href = whatsappThankYouUrl;
}, 650);
};
document.querySelectorAll("[data-lead-form], [data-estimate-email-form]").forEach((form) => {
form.addEventListener("submit", (event) => validateEmailFormSetup(form, event));
});
document.querySelectorAll("[data-booking-form]").forEach((bookingForm) => {
const whatsappSubmit = bookingForm.querySelector("[data-whatsapp-submit]");
whatsappSubmit?.addEventListener("click", () => {
if (!bookingForm.reportValidity()) return;
const data = new FormData(bookingForm);
const businessState = getBusinessHoursState();
const slotLabel = getBookingSlotLabel(data.get("slot"));
const slotKey = getBookingSlotKey(data.get("slot"));
const outOfHoursText = isOutOfHoursKey(slotKey) ? "£50 applied" : "Not applied";
const lines = [
"Hi Tuned Performance, I would like a quote.",
`Name: ${data.get("name") || ""}`,
`Phone: ${data.get("phone") || ""}`,
`Email: ${data.get("email") || ""}`,
`Postcode or area: ${data.get("postcode") || ""}`,
`Vehicle: ${data.get("vehicle") || ""}`,
`Service: ${data.get("service") || ""}`,
`Preferred availability: ${slotLabel}`,
`Evening booking fee: ${outOfHoursText}`,
`Current booking status: ${businessState.statusText}`,
`Business hours: ${BUSINESS_HOURS_SUMMARY} ${OUT_OF_HOURS_SUMMARY}`,
`Details: ${data.get("message") || ""}`
];
const message = encodeURIComponent(lines.join("\n"));
openWhatsAppLead(`https://wa.me/447347388893?text=${message}`);
});
});
const buildBookingLeadPreview = (bookingForm) => {
const data = new FormData(bookingForm);
const businessState = getBusinessHoursState();
const slotLabel = getBookingSlotLabel(data.get("slot"));
const slotKey = getBookingSlotKey(data.get("slot"));
const outOfHoursText = isOutOfHoursKey(slotKey) ? "£50 applied" : "Not applied";
const lines = [
"New Tuned Performance website enquiry",
`Name: ${data.get("name") || ""}`,
`Phone: ${data.get("phone") || ""}`,
`Email: ${data.get("email") || ""}`,
`Postcode or area: ${data.get("postcode") || ""}`,
`Vehicle: ${data.get("vehicle") || ""}`,
`Service: ${data.get("service") || ""}`,
`Preferred availability: ${slotLabel}`,
`Evening booking fee: ${outOfHoursText}`,
`Current booking status: ${businessState.statusText}`,
`Business hours: ${BUSINESS_HOURS_SUMMARY} ${OUT_OF_HOURS_SUMMARY}`,
`Details: ${data.get("message") || ""}`
];
return lines.join("\n");
};
document.querySelectorAll("[data-booking-form]").forEach((bookingForm) => {
const updatePreview = () => {
let summary = bookingForm.querySelector('input[name="enquiry_summary"]');
if (!summary) {
summary = document.createElement("input");
summary.type = "hidden";
summary.name = "enquiry_summary";
bookingForm.append(summary);
}
summary.value = buildBookingLeadPreview(bookingForm);
};
bookingForm.addEventListener("input", updatePreview);
bookingForm.addEventListener("change", updatePreview);
updatePreview();
});
const fullEstimator = document.querySelector("[data-full-estimator]");
const fullName = document.querySelector("[data-full-name]");
const fullPhone = document.querySelector("[data-full-phone]");
const fullEmail = document.querySelector("[data-full-email]");
const fullContact = document.querySelector("[data-full-contact]");
const fullService = document.querySelector("[data-full-service]");
const fullSize = document.querySelector("[data-full-size]");
const fullSlot = document.querySelector("[data-full-slot]");
const fullArea = document.querySelector("[data-full-area]");
const fullVehicle = document.querySelector("[data-full-vehicle]");
const fullColour = document.querySelector("[data-full-colour]");
const fullAccess = document.querySelector("[data-full-access]");
const fullUrgency = document.querySelector("[data-full-urgency]");
const fullDetails = document.querySelector("[data-full-details]");
const fullTotal = document.querySelector("[data-full-total]");
const fullBreakdown = document.querySelector("[data-full-breakdown]");
const fullWhatsApp = document.querySelector("[data-full-whatsapp]");
const estimateEmailForm = document.querySelector("[data-estimate-email-form]");
const estimateServiceLabel = document.querySelector("[data-estimate-service-label]");
const estimateSizeLabel = document.querySelector("[data-estimate-size-label]");
const estimateGuide = document.querySelector("[data-estimate-guide]");
const estimateSummary = document.querySelector("[data-estimate-summary]");
const estimatorWizard = document.querySelector("[data-estimator-wizard]");
let validateEstimatorAll = null;
const fullEstimateData = {
oil: {
label: "Oil and filter service",
small: { amount: 50, note: "Routine oil and filter service" },
medium: { amount: 70, note: "Oil service plus extra filters or checks" },
large: { amount: null, note: "Vehicle and parts review needed" }
},
plugs: {
label: "Spark plugs and ignition coils",
small: { amount: 50, note: "Spark plug or simple ignition service" },
medium: { amount: 80, note: "Multiple plugs or ignition coils" },
large: { amount: null, note: "Vehicle and parts review needed" }
},
brakes: {
label: "Brakes, pads and discs",
small: { amount: 60, note: "Brake inspection or smaller axle job" },
medium: { amount: 120, note: "Pads and discs or more involved brake work" },
large: { amount: null, note: "Vehicle and parts review needed" }
},
wheels: {
label: "Tyres and wheel replacement",
small: { amount: 25, note: "Single wheel change or simple swap" },
medium: { amount: 50, note: "Two wheels or more involved change" },
large: { amount: null, note: "Vehicle and parts review needed" }
},
bumper: {
label: "Bumper scratches or bumper replacement",
small: { amount: 60, note: "Small scuff or localised bumper repair" },
medium: { amount: 120, note: "Medium bumper repair or two affected areas" },
large: { amount: null, note: "Photo quote needed for larger bumper repair" }
},
panel: {
label: "Single panel repair and re-spray",
small: { amount: 100, note: "Single panel starting guide" },
medium: { amount: 160, note: "More visible or wider panel repair" },
large: { amount: null, note: "Panel review needed" }
},
scan: {
label: "OBD diagnostics and fault code scan",
small: { amount: 50, note: "Fault code scan and basic next-step guidance" },
medium: { amount: 75, note: "Fault code scan plus extended checks" },
large: { amount: null, note: "Complex repair diagnosis not included" }
},
upgrades: {
label: "Screen, cluster or trim upgrade",
small: { amount: 30, note: "Simple supplied trim or accessory fitment" },
medium: { amount: 60, note: "Screen, cluster or multi-part upgrade" },
large: { amount: null, note: "Parts review needed" }
},
coding: {
label: "BMW and MINI coding",
small: { amount: 40, note: "Supported feature coding session" },
medium: { amount: 60, note: "Multiple supported coding changes" },
large: { amount: null, note: "Compatibility review needed first" }
}
};
const slotLabels = BOOKING_SLOT_LABELS;