-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.js
More file actions
136 lines (110 loc) · 4.41 KB
/
Copy pathmain.js
File metadata and controls
136 lines (110 loc) · 4.41 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
// 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;
// Scroll to position that shows the section title with proper spacing
const scrollPosition = sectionTop - headerHeight - padding;
window.scrollTo({
top: Math.max(0, scrollPosition),
behavior: 'smooth'
});
}
// 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');
setTimeout(function() {
loadingScreen.remove();
}, 1200);
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);
}
window.addEventListener('scroll', onScroll, { passive: true });
window.addEventListener('wheel', onScroll, { passive: true });
window.addEventListener('touchmove', onScroll, { passive: true });
window.addEventListener('load', function() {
setTimeout(function() {
hideLoadingScreen();
}, 6500);
});
}
// Newsletter form submission handler
function initNewsletterForm() {
const form = document.getElementById('newsletter-form');
if (!form) return;
const emailInput = document.getElementById('newsletter-email');
const messageDiv = document.getElementById('newsletter-message');
const submitButton = form.querySelector('button[type="submit"]');
form.addEventListener('submit', async function(e) {
e.preventDefault();
submitButton.disabled = true;
submitButton.textContent = 'Subscribing...';
messageDiv.textContent = '';
messageDiv.className = 'newsletter-message';
const email = emailInput.value.trim();
if (!email || !email.includes('@')) {
showMessage('Please enter a valid email address.', 'error');
submitButton.disabled = false;
submitButton.textContent = 'Subscribe';
return;
}
try {
const response = await fetch('/api/newsletter', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email }),
});
const data = await response.json();
if (response.ok && data.success) {
showMessage('You\'re subscribed! We\'ll keep you updated.', 'success');
form.reset();
} else {
showMessage(data.error || 'Something went wrong. Please try again.', 'error');
}
} catch (error) {
console.error('Error subscribing:', error);
showMessage('Network error. Please try again.', 'error');
} finally {
submitButton.disabled = false;
submitButton.textContent = 'Subscribe';
}
});
function showMessage(message, type) {
messageDiv.textContent = message;
messageDiv.className = `newsletter-message ${type}`;
}
}
document.addEventListener('DOMContentLoaded', function() {
initLoadingScreen();
// Set up scroll handlers for anchor links
const registerLinks = document.querySelectorAll('a[href="#register"]');
registerLinks.forEach(link => {
link.addEventListener('click', (e) => scrollToSection('register', e));
});
const scheduleLinks = document.querySelectorAll('a[href="#schedule"]');
scheduleLinks.forEach(link => {
link.addEventListener('click', (e) => scrollToSection('schedule', e));
});
initNewsletterForm();
});