-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
153 lines (124 loc) · 5.05 KB
/
Copy pathscript.js
File metadata and controls
153 lines (124 loc) · 5.05 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
document.querySelectorAll('.service-card').forEach((el) => {
observer.observe(el);
});
// Form submission handling
const form = document.getElementById('contact-form');
const status = document.getElementById('form-status');
async function handleSubmit(event)
{
event.preventDefault();
const data = new FormData(event.target);
try {
const response = await fetch(event.target.action, {
method: form.method,
body: data,
headers: { 'Accept': 'application/json' }
});
if (response.ok) {
status.innerHTML = "Thanks for your message! I'll respond shortly.";
status.classList.add('success');
status.classList.remove('error');
form.reset();
} else {
const errorData = await response.json();
status.innerHTML = errorData.errors
? errorData.errors.map(error => error.message).join(', ')
: "Oops! There was a problem submitting your form";
status.classList.add('error');
status.classList.remove('success');
}
} catch (error) {
status.innerHTML = "Oops! There was a problem submitting your form";
status.classList.add('error');
status.classList.remove('success');
}
status.style.display = 'block';
}
/* Hamburger dropdown */
function myFunction() {
var x = document.getElementById("myLinks");
x.style.display = x.style.display === "block" ? "none" : "block";
}
document.addEventListener("click", function (e) {
if (e.target.closest(".hamburger")) return;
document.getElementById("myLinks").style.display = "none";
});
document.addEventListener('DOMContentLoaded', function() {
const backToTop = document.getElementById('back-to-top');
const showAfter =300;
window.addEventListener('scroll', () => {
if (window.scrollY > showAfter) {
backToTop.classList.add('visible');
} else {
backToTop.classList.remove('visible');
}
});
});
// Cookie Consent Handling
document.addEventListener("DOMContentLoaded", function() {
const banner = document.getElementById("cookie-banner");
const modal = document.getElementById("cookie-modal");
const manageBtn = document.getElementById("manage-cookies");
const acceptAllBtn = document.getElementById("accept-all");
const savePreferencesBtn = document.getElementById("save-preferences");
const analyticsCheckbox = document.getElementById("analytics-cookies");
const marketingCheckbox = document.getElementById("marketing-cookies");
const savedPreferences = JSON.parse(localStorage.getItem("cookiePreferences")) || {};
analyticsCheckbox.checked = savedPreferences.analytics || false;
marketingCheckbox.checked = savedPreferences.marketing || false;
if (savedPreferences.essential) {
banner.style.display = "none";
modal.style.display = "none";
loadCookies();
} else {
banner.style.display = "flex";
modal.style.display = "none";
}
manageBtn.addEventListener("click", function() {
modal.style.display = "block";
});
acceptAllBtn.addEventListener("click", function() {
savePreferences({ essential: true, analytics: true, marketing: true });
});
savePreferencesBtn.addEventListener("click", function () {
savePreferences({
essential: true,
analytics: analyticsCheckbox.checked,
marketing: marketingCheckbox.checked
});
});
function savePreferences(preferences) {
localStorage.setItem("cookiePreferences", JSON.stringify(preferences));
banner.style.display = "none";
modal.style.display = "none"; // Hide modal after saving preferences
loadCookies();
}
function loadCookies() {
const preferences = JSON.parse(localStorage.getItem("cookiePreferences")) || {};
if (preferences.analytics) {
loadGoogleAnalytics();
}
if (preferences.marketing) {
loadMarketingScripts();
}
}
function loadGoogleAnalytics() {
console.log("Google Analytics Loaded!");
const script = document.createElement("script");
script.async = true;
script.src = "https://www.googletagmanager.com/gtag/js?id=G-T3VV570ZD6";
document.head.appendChild(script);
script.onload = function () {
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
window.gtag = gtag;
gtag('js', new Date());
gtag('config', 'G-T3VV570ZD6'); // Replace with your actual GA ID
};
}
function loadMarketingScripts() {
console.log("Marketing Scripts Loaded");
}
// Run cookie preferences check on page load
loadCookies();
});