-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
211 lines (198 loc) · 7.54 KB
/
Copy pathscript.js
File metadata and controls
211 lines (198 loc) · 7.54 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
/* ============ WEIRD ATMA — interactions ============ */
(function () {
"use strict";
var prefersReduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
/* ----- Nav scroll state ----- */
var nav = document.getElementById("nav");
var onScroll = function () {
nav.classList.toggle("is-scrolled", window.scrollY > 24);
};
window.addEventListener("scroll", onScroll, { passive: true });
onScroll();
/* ----- Mobile menu ----- */
var burger = document.getElementById("burger");
var links = document.getElementById("navLinks");
burger.addEventListener("click", function () {
var open = links.classList.toggle("is-open");
burger.classList.toggle("is-open", open);
burger.setAttribute("aria-expanded", open ? "true" : "false");
document.body.style.overflow = open ? "hidden" : "";
});
links.addEventListener("click", function (e) {
if (e.target.tagName === "A") {
links.classList.remove("is-open");
burger.classList.remove("is-open");
burger.setAttribute("aria-expanded", "false");
document.body.style.overflow = "";
}
});
/* ----- Clean URLs: smooth-scroll anchors without leaving # in the address bar ----- */
document.addEventListener("click", function (e) {
var a = e.target.closest ? e.target.closest('a[href^="#"]') : null;
if (!a) return;
var id = a.getAttribute("href").slice(1);
var target = id ? document.getElementById(id) : null;
e.preventDefault();
if (target) {
target.scrollIntoView({ behavior: prefersReduced ? "auto" : "smooth" });
} else {
window.scrollTo({ top: 0, behavior: prefersReduced ? "auto" : "smooth" });
}
history.replaceState(null, "", window.location.pathname + window.location.search);
});
if (window.location.hash) {
history.replaceState(null, "", window.location.pathname + window.location.search);
}
/* ----- Contact form: submit in background, show toast ----- */
var form = document.getElementById("leadForm");
var toast = document.getElementById("toast");
var toastTimer = null;
var showToast = function (msg, isError) {
toast.textContent = msg;
toast.classList.toggle("toast--error", !!isError);
toast.classList.add("toast--show");
clearTimeout(toastTimer);
toastTimer = setTimeout(function () {
toast.classList.remove("toast--show");
}, 5000);
};
if (form) {
form.addEventListener("submit", function (e) {
e.preventDefault();
var btn = form.querySelector('button[type="submit"]');
var originalText = btn.textContent;
btn.disabled = true;
btn.textContent = "Sending…";
var data = {};
new FormData(form).forEach(function (value, key) { data[key] = value; });
fetch("https://formsubmit.co/ajax/atmaweird@gmail.com", {
method: "POST",
headers: { "Content-Type": "application/json", "Accept": "application/json" },
body: JSON.stringify(data)
})
.then(function (res) {
if (!res.ok) throw new Error("bad status");
return res.json();
})
.then(function () {
form.reset();
showToast("✓ Got it! We'll get back to you within 24 hours.");
})
.catch(function () {
showToast("Something went wrong — please WhatsApp us instead.", true);
})
.finally(function () {
btn.disabled = false;
btn.textContent = originalText;
});
});
}
/* ----- YouTube lite embeds: load the player only when clicked ----- */
document.querySelectorAll(".yt[data-yt]").forEach(function (card) {
card.addEventListener("click", function () {
if (card.querySelector("iframe")) return;
var id = card.getAttribute("data-yt");
var iframe = document.createElement("iframe");
iframe.src = "https://www.youtube-nocookie.com/embed/" + id + "?autoplay=1&rel=0";
iframe.title = card.getAttribute("aria-label") || "YouTube video";
iframe.allow = "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share";
iframe.allowFullscreen = true;
card.appendChild(iframe);
var play = card.querySelector(".yt__play");
var label = card.querySelector(".yt__label");
if (play) play.remove();
if (label) label.remove();
}, { once: false });
});
/* ----- Scroll reveal ----- */
var revealEls = document.querySelectorAll(".reveal");
if ("IntersectionObserver" in window && !prefersReduced) {
var io = new IntersectionObserver(
function (entries) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
entry.target.classList.add("is-visible");
io.unobserve(entry.target);
}
});
},
{ threshold: 0.12, rootMargin: "0px 0px -40px 0px" }
);
revealEls.forEach(function (el, i) {
el.style.transitionDelay = (i % 4) * 60 + "ms";
io.observe(el);
});
} else {
revealEls.forEach(function (el) { el.classList.add("is-visible"); });
}
/* ----- Animated counters ----- */
var counters = document.querySelectorAll("[data-count]");
var animateCounter = function (el) {
var target = parseInt(el.getAttribute("data-count"), 10);
var suffix = el.getAttribute("data-suffix") || "";
if (prefersReduced) { el.textContent = target + suffix; return; }
var start = null;
var dur = 1400;
var step = function (ts) {
if (!start) start = ts;
var p = Math.min((ts - start) / dur, 1);
var eased = 1 - Math.pow(1 - p, 3);
el.textContent = Math.round(target * eased) + suffix;
if (p < 1) requestAnimationFrame(step);
};
requestAnimationFrame(step);
};
if ("IntersectionObserver" in window) {
var cio = new IntersectionObserver(
function (entries) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
animateCounter(entry.target);
cio.unobserve(entry.target);
}
});
},
{ threshold: 0.6 }
);
counters.forEach(function (el) { cio.observe(el); });
} else {
counters.forEach(function (el) { el.textContent = el.getAttribute("data-count") + (el.getAttribute("data-suffix") || ""); });
}
/* ----- The eye follows the cursor / scroll ----- */
var irisG = document.querySelector(".hero-eye__iris-g");
var eye = document.querySelector(".hero-eye");
if (irisG && eye && !prefersReduced) {
var eyeRect = null;
var updateRect = function () { eyeRect = eye.getBoundingClientRect(); };
updateRect();
window.addEventListener("resize", updateRect);
window.addEventListener("scroll", updateRect, { passive: true });
var moveIris = function (x, y) {
if (!eyeRect) return;
var cx = eyeRect.left + eyeRect.width / 2;
var cy = eyeRect.top + eyeRect.height / 2;
var dx = x - cx;
var dy = y - cy;
var dist = Math.sqrt(dx * dx + dy * dy) || 1;
var max = 13; // max travel in SVG units
var f = Math.min(dist / 180, 1) * max;
irisG.style.transform =
"translate(" + (dx / dist) * f + "px," + (dy / dist) * f + "px)";
};
var fine = window.matchMedia("(pointer: fine)").matches;
if (fine) {
window.addEventListener("mousemove", function (e) {
moveIris(e.clientX, e.clientY);
}, { passive: true });
} else {
// On touch devices the eye slowly wanders on its own
var t = 0;
setInterval(function () {
t += 1;
var a = t * 0.9;
irisG.style.transform =
"translate(" + Math.cos(a) * 9 + "px," + (Math.sin(a * 1.3) * 7) + "px)";
}, 900);
}
}
})();