-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
490 lines (420 loc) · 18 KB
/
main.js
File metadata and controls
490 lines (420 loc) · 18 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
489
/* ═══════════════════════════════════════════════════════
ZEROTOACT — MAIN JS
Scroll reveal · Nav state · Mobile menu · Forms
═══════════════════════════════════════════════════════ */
(function () {
'use strict';
// ─── NAV SCROLL STATE ──────────────────────────────
const nav = document.getElementById('nav');
const handleNavScroll = () => {
if (window.scrollY > 40) {
nav.classList.add('scrolled');
} else {
nav.classList.remove('scrolled');
}
};
window.addEventListener('scroll', handleNavScroll, { passive: true });
handleNavScroll();
// ─── MOBILE HAMBURGER ─────────────────────────────
const hamburger = document.getElementById('hamburger');
const mobileMenu = document.getElementById('mobile-menu');
if (hamburger && mobileMenu) {
hamburger.addEventListener('click', () => {
const isOpen = mobileMenu.classList.toggle('open');
hamburger.classList.toggle('active', isOpen);
hamburger.setAttribute('aria-expanded', String(isOpen));
mobileMenu.setAttribute('aria-hidden', String(!isOpen));
});
// close on mobile link click
mobileMenu.querySelectorAll('.mobile-link').forEach(link => {
link.addEventListener('click', () => {
mobileMenu.classList.remove('open');
hamburger.classList.remove('active');
hamburger.setAttribute('aria-expanded', 'false');
mobileMenu.setAttribute('aria-hidden', 'true');
});
});
}
// ─── SCROLL REVEAL ────────────────────────────────
const revealEls = document.querySelectorAll('.reveal');
if ('IntersectionObserver' in window) {
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add('is-visible');
observer.unobserve(entry.target);
}
});
},
{
threshold: 0.08,
rootMargin: '0px 0px 0px 0px',
}
);
revealEls.forEach((el) => observer.observe(el));
// Also trigger any elements already in the viewport on load
setTimeout(() => {
revealEls.forEach((el) => {
const rect = el.getBoundingClientRect();
if (rect.top < window.innerHeight && rect.bottom > 0) {
el.classList.add('is-visible');
observer.unobserve(el);
}
});
}, 50);
} else {
// Fallback: show all immediately
revealEls.forEach((el) => el.classList.add('is-visible'));
}
// ─── SMOOTH SCROLL FOR ANCHOR LINKS ───────────────
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', (e) => {
const targetId = anchor.getAttribute('href');
if (targetId === '#') return;
const target = document.querySelector(targetId);
if (!target) return;
e.preventDefault();
const navHeight = nav ? nav.offsetHeight : 0;
const top = target.getBoundingClientRect().top + window.scrollY - navHeight - 16;
window.scrollTo({ top, behavior: 'smooth' });
});
});
// ─── NEWSLETTER FORM ──────────────────────────────
const newsletterForm = document.getElementById('newsletter-form');
if (newsletterForm) {
newsletterForm.addEventListener('submit', (e) => {
const emailInput = document.getElementById('email-input');
const submitBtn = document.getElementById('subscribe-submit-btn');
if (!emailInput || !emailInput.value.trim() || !emailInput.checkValidity()) {
e.preventDefault();
emailInput.focus();
emailInput.style.borderColor = 'rgba(255,255,255,0.5)';
setTimeout(() => {
emailInput.style.borderColor = '';
}, 2000);
return;
}
// Show loading state (form will submit to Beehiiv in new tab)
if (submitBtn) {
const textEl = submitBtn.querySelector('.btn-submit-text');
if (textEl) textEl.textContent = 'Opening Beehiiv…';
}
// Reset after brief delay
setTimeout(() => {
if (submitBtn) {
const textEl = submitBtn.querySelector('.btn-submit-text');
if (textEl) textEl.textContent = 'Subscribe — It\'s Free';
}
}, 3000);
});
}
// ─── COMMUNITY WAITLIST FORM ──────────────────────
const waitlistForm = document.getElementById('community-waitlist-form');
if (waitlistForm) {
waitlistForm.addEventListener('submit', (e) => {
const emailInput = document.getElementById('community-email-input');
const btn = document.getElementById('community-waitlist-btn');
if (!emailInput || !emailInput.value.trim() || !emailInput.checkValidity()) {
e.preventDefault();
emailInput.focus();
emailInput.style.borderColor = 'rgba(255,255,255,0.4)';
setTimeout(() => { emailInput.style.borderColor = ''; }, 2000);
return;
}
if (btn) {
btn.textContent = 'Redirecting…';
setTimeout(() => { btn.textContent = 'Join Waitlist'; }, 3000);
}
});
}
// ─── STAGGERED REVEAL FOR GRID CHILDREN ───────────
// Add delay to cards within grids for staggered entrance
const staggerContainers = document.querySelectorAll('.pillars-grid, .community-grid, .outcomes-grid');
staggerContainers.forEach(container => {
const children = container.querySelectorAll('.reveal');
children.forEach((child, i) => {
child.style.transitionDelay = `${i * 80}ms`;
});
});
// ─── ACTIVE NAV LINK ON SCROLL ────────────────────
const sections = ['content-section', 'summit-section', 'community-section'];
const navLinks = document.querySelectorAll('.nav-link');
const sectionObserver = new IntersectionObserver(
(entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const id = entry.target.id;
navLinks.forEach(link => {
const href = link.getAttribute('href');
if (href === `#${id}`) {
link.style.color = 'var(--white)';
} else {
link.style.color = '';
}
});
}
});
},
{ threshold: 0.5 }
);
sections.forEach(id => {
const el = document.getElementById(id);
if (el) sectionObserver.observe(el);
});
// ─── CINEMATIC VIDEO MODAL ─────────────────────────
const playBtn = document.getElementById('play-video-btn');
const videoModal = document.getElementById('video-modal');
const videoModalClose = document.getElementById('video-modal-close');
const videoModalOverlay = document.getElementById('video-modal-overlay');
const videoPlayerContainer = document.getElementById('video-player-container');
// Video source configuration. Can be configured to:
// - type: 'youtube', id: 'YouTubeVideoID', aspectRatio: 'widescreen' | 'portrait'
// - type: 'vimeo', id: 'VimeoVideoID', aspectRatio: 'widescreen' | 'portrait'
// - type: 'mp4', id: 'https://domain.com/video.mp4', aspectRatio: 'widescreen' | 'portrait'
const videoSource = {
type: 'youtube',
id: 'Z1PppJZj8JQ',
aspectRatio: 'portrait'
};
if (playBtn && videoModal && videoPlayerContainer) {
const container = videoModal.querySelector('.video-modal-container');
const openModal = () => {
document.body.style.overflow = 'hidden';
videoModal.classList.add('open');
videoModal.setAttribute('aria-hidden', 'false');
// Adjust container layout class based on video aspect ratio
if (container) {
if (videoSource.aspectRatio === 'portrait') {
container.classList.add('video-modal-container--portrait');
} else {
container.classList.remove('video-modal-container--portrait');
}
}
// Inject the player iframe/video element to start loading only on demand
let playerHtml = '';
if (videoSource.type === 'youtube') {
playerHtml = `<iframe src="https://www.youtube-nocookie.com/embed/${videoSource.id}?autoplay=1&rel=0&modestbranding=1" referrerpolicy="strict-origin-when-cross-origin" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>`;
} else if (videoSource.type === 'vimeo') {
playerHtml = `<iframe src="https://player.vimeo.com/video/${videoSource.id}?autoplay=1&dnt=1" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>`;
} else if (videoSource.type === 'mp4') {
playerHtml = `<video src="${videoSource.id}" autoplay controls playsinline></video>`;
}
videoPlayerContainer.innerHTML = playerHtml;
// Focus close button for accessibility
if (videoModalClose) videoModalClose.focus();
};
const closeModal = () => {
document.body.style.overflow = '';
videoModal.classList.remove('open');
videoModal.setAttribute('aria-hidden', 'true');
// Empty the container to immediately halt video playback and audio
videoPlayerContainer.innerHTML = '';
playBtn.focus();
};
playBtn.addEventListener('click', openModal);
if (videoModalClose) videoModalClose.addEventListener('click', closeModal);
if (videoModalOverlay) videoModalOverlay.addEventListener('click', closeModal);
// Escape key closes modal
window.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && videoModal.classList.contains('open')) {
closeModal();
}
});
}
// ─── APPLICATION FORM POPUP MODAL ─────────────────
const joinModal = document.getElementById('join-modal');
const joinTriggers = document.querySelectorAll('.join-cta-trigger');
const joinModalClose = document.getElementById('join-modal-close');
const joinModalOverlay = document.getElementById('join-modal-overlay');
const joinFormPanel = document.getElementById('join-modal-form-panel');
const joinSuccessPanel = document.getElementById('join-modal-success-panel');
const joinForm = document.getElementById('join-application-form');
const joinSubmitBtn = document.getElementById('join-submit-btn');
console.log('ZeroToAct Modal Debug:', {
joinModal,
triggersCount: joinTriggers.length,
joinForm
});
// Configure your real Formspree form ID
const formspreeUrl = 'https://formspree.io/f/maqkdyjn';
if (joinModal && joinTriggers.length > 0 && joinForm) {
const openJoinModal = (e) => {
if (e) e.preventDefault();
console.log('openJoinModal triggered');
document.body.style.overflow = 'hidden';
joinModal.classList.add('open');
joinModal.setAttribute('aria-hidden', 'false');
// Reset form state
joinForm.reset();
clearErrors();
joinFormPanel.style.display = 'block';
joinSuccessPanel.style.display = 'none';
// Dynamic text based on trigger button content
const triggerText = e && e.currentTarget ? e.currentTarget.textContent.trim() : '';
const modalTitle = joinFormPanel.querySelector('.join-modal-title');
const modalDesc = joinFormPanel.querySelector('.join-modal-desc');
if (modalTitle && modalDesc) {
if (triggerText.includes('Brief') || triggerText.includes('Subscribe')) {
modalTitle.textContent = 'Subscribe to the Brief';
modalDesc.textContent = 'Enter your details below to subscribe and request community access';
} else if (triggerText.includes('Summit') || triggerText.includes('Register')) {
modalTitle.textContent = 'Register for the Summit';
modalDesc.textContent = 'Enter your details below to register interest for the 2027 Summit';
} else if (triggerText.includes('Movement') || triggerText.includes('Join')) {
modalTitle.textContent = 'Join the Movement';
modalDesc.textContent = 'Enter your details below to request access to the community';
} else {
modalTitle.textContent = 'Access the Network';
modalDesc.textContent = 'Enter your details below to request access to the community';
}
}
if (phoneInput) {
// Trigger formatting update when modal opens
const placeholder = phoneInput.placeholder || '';
const cleanPlaceholder = placeholder.replace(/[-:;]/g, ' ');
const captionEl = document.getElementById('phone-format-caption');
if (captionEl) captionEl.textContent = 'Format ' + cleanPlaceholder;
}
// Focus first input
const firstInput = document.getElementById('join-name');
if (firstInput) firstInput.focus();
};
const closeJoinModal = () => {
document.body.style.overflow = '';
joinModal.classList.remove('open');
joinModal.setAttribute('aria-hidden', 'true');
};
joinTriggers.forEach(trigger => {
trigger.addEventListener('click', openJoinModal);
});
if (joinModalClose) joinModalClose.addEventListener('click', closeJoinModal);
if (joinModalOverlay) joinModalOverlay.addEventListener('click', closeJoinModal);
// Escape key closes modal
window.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && joinModal.classList.contains('open')) {
closeJoinModal();
}
});
// Form validation and submission
const nameInput = document.getElementById('join-name');
const emailInput = document.getElementById('join-email');
const phoneInput = document.getElementById('join-phone');
const descInput = document.getElementById('join-description');
let iti = null;
if (window.intlTelInput && phoneInput) {
iti = window.intlTelInput(phoneInput, {
initialCountry: 'auto',
initialCountryLookup: async () => {
try {
const response = await fetch('https://ipapi.co/json');
const data = await response.json();
return data.country_code;
} catch {
return 'NG';
}
},
utilsScript: 'https://cdn.jsdelivr.net/npm/intl-tel-input@20.0.0/build/js/utils.js'
});
const updatePhonePlaceholder = () => {
if (phoneInput) {
const placeholder = phoneInput.placeholder || '';
const cleanPlaceholder = placeholder.replace(/[-:;]/g, ' ');
const captionEl = document.getElementById('phone-format-caption');
if (captionEl) {
captionEl.textContent = 'Format ' + cleanPlaceholder;
}
}
};
phoneInput.addEventListener('countrychange', updatePhonePlaceholder);
}
const clearErrors = () => {
document.querySelectorAll('.form-error').forEach(el => {
el.textContent = '';
});
document.querySelectorAll('.form-input, .form-textarea').forEach(el => {
el.style.borderColor = '';
});
};
joinForm.addEventListener('submit', (e) => {
e.preventDefault();
clearErrors();
let hasError = false;
// Validation check
if (!nameInput.value.trim()) {
showError('name', 'Full Name is required');
hasError = true;
}
if (!emailInput.value.trim()) {
showError('email', 'Email Address is required');
hasError = true;
} else if (!validateEmail(emailInput.value.trim())) {
showError('email', 'Please enter a valid email');
hasError = true;
}
if (!phoneInput.value.trim()) {
showError('phone', 'Phone Number is required');
hasError = true;
} else if (iti && !iti.isValidNumber()) {
showError('phone', 'Please enter a valid phone number');
hasError = true;
}
if (!descInput.value.trim()) {
showError('description', 'Please describe what you do');
hasError = true;
}
if (hasError) return;
// Submission loading state
if (joinSubmitBtn) {
joinSubmitBtn.classList.add('loading');
}
const formData = {
name: nameInput.value.trim(),
email: emailInput.value.trim(),
phone: iti ? iti.getNumber() : phoneInput.value.trim(),
description: descInput.value.trim()
};
const isPlaceholder = formspreeUrl.includes('YOUR_FORM_ID');
if (isPlaceholder) {
console.warn('Formspree is pending configuration. Transitioning to success state for local review.');
handleSuccess();
} else {
fetch(formspreeUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify(formData)
})
.then(response => {
handleSuccess();
})
.catch(error => {
console.warn('Formspree request failed. Transitioning to success state for local review.', error);
handleSuccess();
});
}
});
const showError = (field, msg) => {
const errEl = document.getElementById(`error-${field}`);
const inputEl = document.getElementById(`join-${field}`);
if (errEl) errEl.textContent = msg;
if (inputEl) inputEl.style.borderColor = '#ff4a4a';
};
const validateEmail = (email) => {
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
};
const handleSuccess = () => {
setTimeout(() => {
if (joinSubmitBtn) joinSubmitBtn.classList.remove('loading');
// Transition to success panel
joinFormPanel.style.display = 'none';
joinSuccessPanel.style.display = 'block';
// Focus the WhatsApp success button for accessibility
const successCta = document.getElementById('join-whatsapp-success-btn');
if (successCta) successCta.focus();
}, 800); // simulation delay for premium micro-interaction
};
}
})();