-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
394 lines (336 loc) · 13.7 KB
/
scripts.js
File metadata and controls
394 lines (336 loc) · 13.7 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
// MindCore Interactions
// Version 2.0 - Enhanced with analytics, FAQ, and improved form handling
document.addEventListener('DOMContentLoaded', () => {
// --- Analytics Placeholder ---
// Replace with your actual analytics (Google Analytics, Mixpanel, etc.)
const analytics = {
track: (event, data = {}) => {
console.log('[Analytics]', event, data);
// Example: gtag('event', event, data);
// Example: mixpanel.track(event, data);
},
page: (pageName) => {
console.log('[Analytics] Page View:', pageName);
// Example: gtag('event', 'page_view', { page_title: pageName });
}
};
// Track page view
analytics.page(document.title);
// --- Mobile Menu ---
const mobileBtn = document.querySelector('.mobile-menu-btn');
const navLinks = document.querySelector('.nav-links');
if (mobileBtn && navLinks) {
mobileBtn.addEventListener('click', () => {
navLinks.classList.toggle('open');
mobileBtn.textContent = navLinks.classList.contains('open') ? '✕' : '☰';
analytics.track('mobile_menu_toggle', { open: navLinks.classList.contains('open') });
});
}
// --- Scroll Reveal ---
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
}, observerOptions);
document.querySelectorAll('[data-animate]').forEach(el => {
observer.observe(el);
});
// --- Modal Logic ---
const modal = document.getElementById('interest-modal');
const openBtns = document.querySelectorAll('[data-open-modal]');
const closeBtns = document.querySelectorAll('[data-close-modal]');
const form = document.getElementById('interest-form');
const successMsg = document.querySelector('.form-success');
function openModal() {
if (!modal) return;
modal.style.display = 'block';
document.body.style.overflow = 'hidden';
requestAnimationFrame(() => {
modal.setAttribute('aria-hidden', 'false');
modal.setAttribute('aria-modal', 'true');
});
analytics.track('modal_open', { modal: 'interest-modal' });
}
function closeModal() {
if (!modal) return;
modal.setAttribute('aria-hidden', 'true');
modal.setAttribute('aria-modal', 'false');
document.body.style.overflow = '';
setTimeout(() => {
modal.style.display = 'none';
if (form) form.reset();
if (successMsg) successMsg.hidden = true;
if (form) form.style.display = 'grid';
}, 300);
analytics.track('modal_close', { modal: 'interest-modal' });
}
openBtns.forEach(btn => btn.addEventListener('click', (e) => {
e.preventDefault();
openModal();
}));
closeBtns.forEach(btn => btn.addEventListener('click', closeModal));
if (modal) {
modal.addEventListener('click', (e) => {
if (e.target.classList.contains('modal-backdrop')) {
closeModal();
}
});
// Close on Escape key
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && modal.getAttribute('aria-hidden') === 'false') {
closeModal();
}
});
}
// --- Form Handling with Netlify Forms Integration ---
const forms = document.querySelectorAll('form[data-netlify="true"]');
forms.forEach(formEl => {
formEl.addEventListener('submit', async (e) => {
e.preventDefault();
const submitBtn = formEl.querySelector('button[type="submit"]');
const originalText = submitBtn ? submitBtn.textContent : '';
const formData = new FormData(formEl);
const statusDiv = formEl.querySelector('[role="status"]');
// Validate email
const emailInput = formEl.querySelector('input[type="email"]');
if (emailInput && !isValidEmail(emailInput.value)) {
showFormError(emailInput, 'Please enter a valid email address');
return;
}
// Show loading state
if (submitBtn) {
submitBtn.disabled = true;
submitBtn.textContent = 'Submitting...';
}
try {
// Submit to Netlify Forms
const response = await fetch('/', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams(formData).toString()
});
if (!response.ok) {
throw new Error('Submission failed');
}
// Track successful submission
analytics.track('form_submitted', {
form_name: formData.get('form-name'),
email: formData.get('email'),
source: formData.get('source') || 'unknown',
page: window.location.pathname
});
// Show success message
if (statusDiv) {
statusDiv.textContent = 'Thank you! We\'ll be in touch soon.';
statusDiv.className = 'form-status success';
}
// Reset form after delay
setTimeout(() => {
formEl.reset();
if (statusDiv) {
statusDiv.className = 'form-status';
statusDiv.textContent = '';
}
// Close modal if inside one
const modal = formEl.closest('.modal');
if (modal) {
closeModal();
}
}, 2500)
// If in modal, auto close
if (modal && modal.contains(formEl)) {
setTimeout(closeModal, 2500);
}
} catch (error) {
console.error('Form submission error:', error);
analytics.track('form_error', {
form_name: formData.get('form-name'),
error: error.message,
page: window.location.pathname
});
// Show error message
if (statusDiv) {
statusDiv.textContent = 'Something went wrong. Please try again.';
statusDiv.className = 'form-status error';
}
} finally {
if (submitBtn) {
submitBtn.disabled = false;
submitBtn.textContent = originalText;
}
}
});
});
function isValidEmail(email) {
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
}
function showFormError(input, message) {
input.style.borderColor = '#ff375f';
// Remove existing error
const existingError = input.parentElement.querySelector('.form-error');
if (existingError) existingError.remove();
const errorEl = document.createElement('span');
errorEl.className = 'form-error';
errorEl.style.cssText = 'color: #ff375f; font-size: 12px; margin-top: 4px; display: block;';
errorEl.textContent = message;
input.parentElement.appendChild(errorEl);
input.addEventListener('input', () => {
input.style.borderColor = '';
errorEl.remove();
}, { once: true });
}
// --- FAQ Accordion ---
const faqItems = document.querySelectorAll('.faq-item');
faqItems.forEach(item => {
const question = item.querySelector('.faq-question');
const answer = item.querySelector('.faq-answer');
if (question && answer) {
question.addEventListener('click', () => {
const isOpen = item.classList.contains('open');
// Close all other items
faqItems.forEach(otherItem => {
if (otherItem !== item && otherItem.classList.contains('open')) {
otherItem.classList.remove('open');
otherItem.querySelector('.faq-question').setAttribute('aria-expanded', 'false');
}
});
// Toggle current item
item.classList.toggle('open');
question.setAttribute('aria-expanded', !isOpen);
analytics.track('faq_toggle', {
question: question.textContent.trim().substring(0, 50),
open: !isOpen
});
});
}
});
// --- Smooth Scroll for Anchor Links ---
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
const targetId = this.getAttribute('href');
if (targetId === '#') return;
const targetElement = document.querySelector(targetId);
if (targetElement) {
e.preventDefault();
targetElement.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
// Update URL without scroll jump
history.pushState(null, null, targetId);
}
});
});
// --- Track CTA Clicks ---
document.querySelectorAll('.btn').forEach(btn => {
btn.addEventListener('click', () => {
analytics.track('cta_click', {
text: btn.textContent.trim(),
href: btn.href || 'no-href',
page: window.location.pathname
});
});
});
// --- Background Particles (Canvas) ---
const canvas = document.getElementById('bg');
if (canvas) {
const ctx = canvas.getContext('2d');
let width, height;
let particles = [];
let animationId;
function resize() {
width = window.innerWidth;
height = window.innerHeight;
canvas.width = width;
canvas.height = height;
}
class Particle {
constructor() {
this.x = Math.random() * width;
this.y = Math.random() * height;
this.size = Math.random() * 2;
this.speedX = Math.random() * 0.5 - 0.25;
this.speedY = Math.random() * 0.5 - 0.25;
this.opacity = Math.random() * 0.5 + 0.1;
}
update() {
this.x += this.speedX;
this.y += this.speedY;
if (this.x > width) this.x = 0;
if (this.x < 0) this.x = width;
if (this.y > height) this.y = 0;
if (this.y < 0) this.y = height;
}
draw() {
ctx.fillStyle = `rgba(255, 255, 255, ${this.opacity})`;
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
ctx.fill();
}
}
function init() {
resize();
particles = [];
for (let i = 0; i < 60; i++) {
particles.push(new Particle());
}
animate();
}
function connectParticles() {
const maxDistance = 150;
for (let a = 0; a < particles.length; a++) {
for (let b = a; b < particles.length; b++) {
const dx = particles[a].x - particles[b].x;
const dy = particles[a].y - particles[b].y;
const distance = Math.sqrt(dx * dx + dy * dy);
if (distance < maxDistance) {
const opacity = 1 - (distance / maxDistance);
ctx.strokeStyle = `rgba(41, 151, 255, ${opacity * 0.15})`; // Blue tint
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(particles[a].x, particles[a].y);
ctx.lineTo(particles[b].x, particles[b].y);
ctx.stroke();
}
}
}
}
function animate() {
ctx.clearRect(0, 0, width, height);
// Draw connections first so particles sit on top
connectParticles();
particles.forEach(p => {
p.update();
p.draw();
});
animationId = requestAnimationFrame(animate);
}
// Pause animation when tab is not visible (performance)
document.addEventListener('visibilitychange', () => {
if (document.hidden) {
cancelAnimationFrame(animationId);
} else {
animate();
}
});
window.addEventListener('resize', resize);
init();
}
// --- Console Easter Egg ---
console.log('%c🧠 MindCore', 'font-size: 24px; font-weight: bold; color: #2997ff;');
console.log('%cBuilding AI that understands you.', 'font-size: 14px; color: #86868b;');
console.log('%cInterested in joining? → careers@mindcore.ai', 'font-size: 12px; color: #30d158;');
// --- Glitch Effect Initialization ---
const glitchElements = document.querySelectorAll('.brand span, h1');
glitchElements.forEach(el => {
el.classList.add('glitch-hover');
el.setAttribute('data-text', el.textContent);
});
});