-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwaitlist.js
More file actions
175 lines (144 loc) · 6 KB
/
waitlist.js
File metadata and controls
175 lines (144 loc) · 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
// Smooth scroll to section, ensuring title is visible
function scrollToSection(sectionId, e) {
const section = document.getElementById(sectionId);
if (!section) return;
e.preventDefault();
// Get header height for offset
const header = document.querySelector('.header');
const headerHeight = header ? header.offsetHeight : 0;
const padding = 40; // Extra padding to ensure title is fully visible
// Calculate position to show section with title visible
const sectionRect = section.getBoundingClientRect();
const sectionTop = sectionRect.top + window.pageYOffset;
const viewportHeight = window.innerHeight;
// Scroll to position that shows the section title with proper spacing
// Position section so it starts below header with padding
const scrollPosition = sectionTop - headerHeight - padding;
// Smooth scroll to position
window.scrollTo({
top: Math.max(0, scrollPosition),
behavior: 'smooth'
});
}
// Smooth scroll to waitlist section, centered on page
function scrollToWaitlist(e) {
scrollToSection('waitlist', e);
}
// Loading screen handler
function initLoadingScreen() {
const loadingScreen = document.getElementById('loading-screen');
if (!loadingScreen) return;
let isHiding = false;
function hideLoadingScreen() {
if (isHiding) return;
isHiding = true;
loadingScreen.classList.add('hidden');
// Remove from DOM after transition completes
setTimeout(function() {
loadingScreen.remove();
}, 1200);
// Clean up scroll listener
window.removeEventListener('scroll', onScroll);
window.removeEventListener('wheel', onScroll);
window.removeEventListener('touchmove', onScroll);
}
function onScroll() {
hideLoadingScreen();
}
const skipButton = document.getElementById('skip-loading');
if (skipButton) {
skipButton.addEventListener('click', hideLoadingScreen);
}
// Hide on scroll, wheel, or touch
window.addEventListener('scroll', onScroll, { passive: true });
window.addEventListener('wheel', onScroll, { passive: true });
window.addEventListener('touchmove', onScroll, { passive: true });
// Wait for page to fully load
window.addEventListener('load', function() {
// Add delay to allow title animation to complete (6s zoom + 4s title = ~6s total)
setTimeout(function() {
hideLoadingScreen();
}, 6500); // Wait for animations to complete
});
}
// Waitlist form submission handler and scroll setup
document.addEventListener('DOMContentLoaded', function() {
// Initialize loading screen
initLoadingScreen();
// Set up scroll handlers for all anchor links
const waitlistLinks = document.querySelectorAll('a[href="#waitlist"]');
waitlistLinks.forEach(link => {
link.addEventListener('click', scrollToWaitlist);
});
const scheduleLinks = document.querySelectorAll('a[href="#schedule"]');
scheduleLinks.forEach(link => {
link.addEventListener('click', (e) => scrollToSection('schedule', e));
});
const form = document.getElementById('waitlist-form');
const emailInput = document.getElementById('waitlist-email');
const nameInput = document.getElementById('waitlist-name');
const involvementInput = document.getElementById('waitlist-involvement');
const messageDiv = document.getElementById('waitlist-message');
const submitButton = form.querySelector('button[type="submit"]');
if (!form) return;
form.addEventListener('submit', async function(e) {
e.preventDefault();
// Disable form during submission
submitButton.disabled = true;
submitButton.textContent = 'Submitting...';
messageDiv.textContent = '';
messageDiv.className = 'waitlist-message';
const email = emailInput.value.trim();
const name = nameInput.value.trim();
// Basic email validation
if (!email || !email.includes('@')) {
showMessage('Please enter a valid email address.', 'error');
submitButton.disabled = false;
submitButton.textContent = 'Submit';
return;
}
// Name is now required
if (!name || name.trim() === '') {
showMessage('Please enter your name.', 'error');
submitButton.disabled = false;
submitButton.textContent = 'Submit';
return;
}
const involvement = involvementInput.value.trim();
// Involvement is required
if (!involvement || involvement === '') {
showMessage('Please describe your desired involvement.', 'error');
submitButton.disabled = false;
submitButton.textContent = 'Submit';
return;
}
try {
const response = await fetch('/api/waitlist', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ email, name, involvement }),
});
const data = await response.json();
if (response.ok && data.success) {
showMessage('Thank you! Your information has been submitted.', 'success');
form.reset();
} else {
showMessage(data.error || 'Something went wrong. Please try again.', 'error');
}
} catch (error) {
console.error('Error submitting form:', error);
showMessage('Network error. Please check your connection and try again.', 'error');
} finally {
submitButton.disabled = false;
submitButton.textContent = 'Submit';
}
});
function showMessage(message, type) {
messageDiv.textContent = message;
messageDiv.className = `waitlist-message ${type}`;
// Scroll message into view if needed
messageDiv.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
}
});