-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsite.js
More file actions
100 lines (93 loc) · 2.96 KB
/
Copy pathsite.js
File metadata and controls
100 lines (93 loc) · 2.96 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
(function () {
var analyticsId = window.LEDGER_ANALYTICS_ID || "";
var consentKey = "ledger-cookie-consent";
function loadAnalytics() {
if (!analyticsId || document.querySelector("script[data-ledger-analytics]"))
return;
var script = document.createElement("script");
script.async = true;
script.src =
"https://www.googletagmanager.com/gtag/js?id=" +
encodeURIComponent(analyticsId);
script.dataset.ledgerAnalytics = "true";
document.head.appendChild(script);
window.dataLayer = window.dataLayer || [];
window.gtag =
window.gtag ||
function () {
window.dataLayer.push(arguments);
};
window.gtag("js", new Date());
window.gtag("config", analyticsId, { anonymize_ip: true });
}
function setConsent(value) {
localStorage.setItem(consentKey, value);
var banner = document.querySelector("[data-cookie-banner]");
if (banner) banner.hidden = true;
if (value === "accepted") loadAnalytics();
}
function setupCookieBanner() {
var banner = document.querySelector("[data-cookie-banner]");
if (!banner || localStorage.getItem(consentKey)) return;
banner.hidden = false;
var accept = banner.querySelector("[data-cookie-accept]");
var decline = banner.querySelector("[data-cookie-decline]");
if (accept)
accept.addEventListener("click", function () {
setConsent("accepted");
});
if (decline)
decline.addEventListener("click", function () {
setConsent("declined");
});
}
function setupLoadingState() {
window.addEventListener("load", function () {
document.documentElement.classList.add("page-ready");
var loader = document.querySelector("[data-page-loader]");
if (loader)
window.setTimeout(function () {
loader.hidden = true;
}, 180);
});
}
function setupMobileCta() {
var cta = document.querySelector("[data-mobile-cta]");
if (!cta) return;
var dismissed = false;
window.addEventListener(
"scroll",
function () {
if (dismissed) return;
cta.classList.toggle("is-visible", window.scrollY > 280);
},
{ passive: true },
);
var close = cta.querySelector("[data-mobile-cta-close]");
if (close)
close.addEventListener("click", function () {
dismissed = true;
cta.classList.remove("is-visible");
});
}
function setupFormState() {
var form = document.querySelector("#contact-form");
var submit = form && form.querySelector("[data-fs-submit-btn]");
if (!form || !submit) return;
form.addEventListener(
"submit",
function () {
submit.disabled = true;
submit.textContent = "Sending...";
},
true,
);
}
document.addEventListener("DOMContentLoaded", function () {
setupCookieBanner();
setupLoadingState();
setupMobileCta();
setupFormState();
if (localStorage.getItem(consentKey) === "accepted") loadAnalytics();
});
})();