-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
193 lines (165 loc) · 6.77 KB
/
main.js
File metadata and controls
193 lines (165 loc) · 6.77 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
/* ═══════════════════════════════════════════════════════
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);
});
})();