-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
488 lines (408 loc) · 14.6 KB
/
script.js
File metadata and controls
488 lines (408 loc) · 14.6 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
/**
* TinyPaws Landing Page JavaScript
* Adds interactivity to the TinyPaws landing page
*/
document.addEventListener("DOMContentLoaded", function () {
// Initialize Feather icons
if (typeof feather !== "undefined") {
feather.replace();
}
// Waitlist Popup Functionality
const waitlistOverlay = document.getElementById("waitlist-overlay");
const openWaitlistBtn = document.getElementById("open-waitlist");
const heroWaitlistBtn = document.getElementById("hero-waitlist-btn");
const closePopupBtn = document.getElementById("close-popup");
const waitlistBtns = document.querySelectorAll(".waitlist-btn");
const waitlistForm = document.getElementById("waitlist-form");
const formError = document.getElementById("form-error");
const formSuccess = document.getElementById("form-success");
// Waitlist ID from the provided code
function openWaitlistPopup() {
waitlistOverlay.classList.add("active");
document.body.style.overflow = "hidden"; // Prevent scrolling when popup is open
}
function closeWaitlistPopup() {
waitlistOverlay.classList.remove("active");
document.body.style.overflow = ""; // Re-enable scrolling
}
// Open popup when clicking on any waitlist button
if (openWaitlistBtn) {
openWaitlistBtn.addEventListener("click", openWaitlistPopup);
}
// Hero section join waitlist button
const heroJoinWaitlistBtn = document.getElementById("hero-join-waitlist");
if (heroJoinWaitlistBtn) {
heroJoinWaitlistBtn.addEventListener("click", openWaitlistPopup);
}
// Mobile menu waitlist button
const mobileWaitlistBtn = document.getElementById("mobile-waitlist");
if (mobileWaitlistBtn) {
mobileWaitlistBtn.addEventListener("click", function () {
// First close the mobile menu
if (navMenu && hamburger) {
navMenu.classList.remove("active");
hamburger.classList.remove("active");
}
// Then open the waitlist popup
openWaitlistPopup();
});
}
if (heroWaitlistBtn) {
heroWaitlistBtn.addEventListener("click", openWaitlistPopup);
}
waitlistBtns.forEach((btn) => {
btn.addEventListener("click", openWaitlistPopup);
});
// Close popup when clicking the close button
if (closePopupBtn) {
closePopupBtn.addEventListener("click", closeWaitlistPopup);
}
// Close popup when clicking outside the popup
waitlistOverlay.addEventListener("click", function (e) {
if (e.target === waitlistOverlay) {
closeWaitlistPopup();
}
});
// Handle main form submission
const mainWaitlistForm = document.querySelector(".hero-cta .waitlist-form");
const mainFormError = document.getElementById("main-form-error");
const mainFormSuccess = document.getElementById("main-form-success");
if (mainWaitlistForm) {
mainWaitlistForm.addEventListener("submit", async function (e) {
e.preventDefault();
// Clear previous messages
mainFormError.textContent = "";
mainFormSuccess.textContent = "";
// Get form data
const email = document.getElementById("email").value.trim();
const name = document.getElementById("name").value.trim();
const petName = document.getElementById("pet-name").value.trim();
const petType = document.getElementById("pet-type").value;
// Basic validation
if (!email) {
mainFormError.textContent = "Please enter your email address";
return;
}
if (!name) {
mainFormError.textContent = "Please enter your name";
return;
}
if (!petName) {
mainFormError.textContent = "Please enter your pet's name";
return;
}
if (!petType) {
mainFormError.textContent = "Please select your pet type";
return;
}
// Disable submit button during API call
const submitBtn = mainWaitlistForm.querySelector('button[type="submit"]');
submitBtn.disabled = true;
submitBtn.textContent = "Joining...";
try {
// Call the new API endpoint
const response = await fetch("/api/join-waitlist", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email,
name,
petName,
petType,
}),
});
const data = await response.json();
if (!data.success) { // Check the 'success' field from our worker
throw new Error(
data.message || "Something went wrong. Please try again."
);
}
mainFormSuccess.textContent = data.message || "Successfully joined! We'll be in touch.";
mainWaitlistForm.reset();
} catch (error) {
mainFormError.textContent =
error.message || "Something went wrong. Please try again.";
} finally {
// Re-enable submit button
submitBtn.disabled = false;
submitBtn.textContent = "JOIN THE WAITLIST";
}
});
}
// Handle popup form submission
if (waitlistForm) {
waitlistForm.addEventListener("submit", async function (e) {
e.preventDefault();
// Clear previous messages
formError.textContent = "";
formSuccess.textContent = "";
// Get form data
const email = document.getElementById("popup-email").value.trim();
const name = document.getElementById("popup-name").value.trim();
const petName = document.getElementById("popup-pet-name").value.trim();
const petType = document.getElementById("popup-pet-type").value;
// Basic validation
if (!email) {
formError.textContent = "Please enter your email address";
return;
}
if (!name) {
formError.textContent = "Please enter your name";
return;
}
if (!petName) {
formError.textContent = "Please enter your pet's name";
return;
}
if (!petType) {
formError.textContent = "Please select your pet type";
return;
}
// Disable submit button during API call
const submitBtn = waitlistForm.querySelector('button[type="submit"]');
submitBtn.disabled = true;
submitBtn.textContent = "Joining...";
try {
// Call the new API endpoint
const response = await fetch("/api/join-waitlist", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email,
name,
petName,
petType,
}),
});
const data = await response.json();
if (!data.success) { // Check the 'success' field from our worker
throw new Error(
data.message || "Something went wrong. Please try again."
);
}
formSuccess.textContent = data.message || "Successfully joined! We'll be in touch.";
waitlistForm.reset();
// After 3 seconds, close the popup
setTimeout(() => {
closeWaitlistPopup();
}, 3000);
} catch (error) {
formError.textContent =
error.message || "Something went wrong. Please try again.";
} finally {
// Re-enable submit button
submitBtn.disabled = false;
submitBtn.textContent = "JOIN THE WAITLIST";
}
});
}
// Mobile Navigation Toggle
const hamburger = document.querySelector(".hamburger");
const navMenu = document.querySelector(".nav-menu");
if (hamburger && navMenu) {
hamburger.addEventListener("click", function () {
navMenu.classList.toggle("active");
hamburger.classList.toggle("active");
});
}
// Close mobile menu when clicking on a nav link
const navLinks = document.querySelectorAll(".nav-links a");
navLinks.forEach((link) => {
link.addEventListener("click", function () {
if (navMenu.classList.contains("active")) {
navMenu.classList.remove("active");
hamburger.classList.remove("active");
}
});
});
// FAQ Accordion
const faqItems = document.querySelectorAll(".faq-item");
faqItems.forEach((item) => {
const question = item.querySelector(".faq-question");
question.addEventListener("click", function () {
// Close all other FAQ items
faqItems.forEach((otherItem) => {
if (otherItem !== item && otherItem.classList.contains("active")) {
otherItem.classList.remove("active");
}
});
// Toggle current FAQ item
item.classList.toggle("active");
});
});
// Smooth scrolling for all anchor links including 'See How It Works'
function smoothScrollTo(targetId) {
if (targetId === "#") return;
const targetElement = document.querySelector(targetId);
if (targetElement) {
const header = document.querySelector(".header");
const headerHeight = header.offsetHeight;
const headerTop = parseInt(window.getComputedStyle(header).top, 10) || 0;
const headerBottom = headerHeight + headerTop;
const headerBottomWithPadding = headerBottom + 20; // Add some extra spacing
const targetPosition =
targetElement.getBoundingClientRect().top +
window.pageYOffset -
headerBottomWithPadding;
window.scrollTo({
top: targetPosition,
behavior: "smooth",
});
}
}
// Apply smooth scrolling to all anchor links
document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
anchor.addEventListener("click", function (e) {
e.preventDefault();
const targetId = this.getAttribute("href");
smoothScrollTo(targetId);
});
});
// We've already handled the main waitlist form above, so this is no longer needed
// If there are any other waitlist forms on the page that aren't handled yet
const otherWaitlistForms = document.querySelectorAll(
".waitlist-form:not(.hero-cta .waitlist-form)"
);
otherWaitlistForms.forEach((form) => {
if (form !== mainWaitlistForm) {
// Avoid handling the same form twice
form.addEventListener("submit", function (e) {
e.preventDefault();
// Open the popup instead
openWaitlistPopup();
});
}
});
// Helper function to validate email
function isValidEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
// Helper function to show form error
function showFormError(inputElement, message) {
// Remove any existing error message
const existingError =
inputElement.parentElement.querySelector(".error-message");
if (existingError) {
existingError.remove();
}
// Create and append error message
const errorElement = document.createElement("div");
errorElement.className = "error-message";
errorElement.textContent = message;
errorElement.style.color = "var(--primary-color)";
errorElement.style.fontSize = "0.9rem";
errorElement.style.marginTop = "0.5rem";
inputElement.parentElement.appendChild(errorElement);
// Highlight input
inputElement.style.borderColor = "var(--primary-color)";
// Remove error when input changes
inputElement.addEventListener(
"input",
function () {
const error = this.parentElement.querySelector(".error-message");
if (error) {
error.remove();
}
this.style.borderColor = "";
},
{ once: true }
);
}
// Testimonial Carousel (simple version)
const testimonials = document.querySelectorAll(".testimonial");
let currentTestimonial = 0;
if (testimonials.length > 1) {
// Hide all testimonials except the first one
testimonials.forEach((testimonial, index) => {
if (index !== 0) {
testimonial.style.display = "none";
}
});
// Create carousel controls
const carouselContainer = document.querySelector(".testimonials-carousel");
const controlsContainer = document.createElement("div");
controlsContainer.className = "carousel-controls";
controlsContainer.style.display = "flex";
controlsContainer.style.justifyContent = "center";
controlsContainer.style.marginTop = "1rem";
testimonials.forEach((_, index) => {
const dot = document.createElement("button");
dot.className = "carousel-dot";
dot.setAttribute("aria-label", `Testimonial ${index + 1}`);
dot.style.width = "12px";
dot.style.height = "12px";
dot.style.borderRadius = "50%";
dot.style.border = "none";
dot.style.margin = "0 5px";
dot.style.cursor = "pointer";
dot.style.backgroundColor =
index === 0 ? "var(--primary-color)" : "var(--border-color)";
dot.addEventListener("click", function () {
showTestimonial(index);
});
controlsContainer.appendChild(dot);
});
carouselContainer.appendChild(controlsContainer);
// Auto-rotate testimonials
setInterval(() => {
currentTestimonial = (currentTestimonial + 1) % testimonials.length;
showTestimonial(currentTestimonial);
}, 5000);
}
function showTestimonial(index) {
testimonials.forEach((testimonial, i) => {
testimonial.style.display = i === index ? "block" : "none";
});
// Update dots
const dots = document.querySelectorAll(".carousel-dot");
dots.forEach((dot, i) => {
dot.style.backgroundColor =
i === index ? "var(--primary-color)" : "var(--border-color)";
});
currentTestimonial = index;
}
// Animated counter for waitlist
const counter = document.querySelector(".counter-number");
if (counter) {
const targetCount = parseInt(counter.textContent);
let currentCount = 0;
const duration = 2000; // 2 seconds
const interval = 20; // Update every 20ms
const increment = Math.ceil(targetCount / (duration / interval));
const counterAnimation = setInterval(() => {
currentCount += increment;
if (currentCount >= targetCount) {
currentCount = targetCount;
clearInterval(counterAnimation);
}
counter.textContent = currentCount;
}, interval);
}
// Add scroll reveal animation with improved performance
const revealElements = document.querySelectorAll(
".feature-card, .step, .plan-card, .point"
);
function checkReveal() {
revealElements.forEach((element) => {
const elementTop = element.getBoundingClientRect().top;
const windowHeight = window.innerHeight;
if (elementTop < windowHeight - 50) {
element.classList.add("revealed");
}
});
}
// Initialize reveal elements with CSS classes instead of inline styles
revealElements.forEach((element) => {
element.classList.add("reveal-element");
});
// Immediately reveal elements that are already in view
setTimeout(checkReveal, 100);
// Check on load and scroll
window.addEventListener("load", checkReveal);
window.addEventListener("scroll", checkReveal);
});