-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
225 lines (193 loc) · 7.06 KB
/
Copy pathscript.js
File metadata and controls
225 lines (193 loc) · 7.06 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
// ---- Supabase setup ----
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';
// TODO: REPLACE THESE TWO VALUES WITH YOUR REAL ONES
const SUPABASE_URL = 'https://uobtilkjzuoocqacgbqi.supabase.co';
const SUPABASE_ANON_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InVvYnRpbGtqenVvb2NxYWNnYnFpIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjMwNTM1OTEsImV4cCI6MjA3ODYyOTU5MX0.o41V0Tp6C9SBwBHgyK6yE3PdDJiIhlzJKaHuGuYA6WY';
const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
// ---- Smooth scrolling for navigation links ----
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
const href = this.getAttribute('href');
if (!href || href === '#') return;
const target = document.querySelector(href);
if (!target) return;
e.preventDefault();
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
});
});
// ---- Contact form handling (sends to contact_leads) ----
const contactForm = document.getElementById('contactForm');
if (contactForm) {
contactForm.addEventListener('submit', async function (e) {
e.preventDefault();
const formData = new FormData(this);
const name = formData.get('name')?.toString().trim();
const email = formData.get('email')?.toString().trim();
const business = formData.get('business')?.toString().trim();
const message = formData.get('message')?.toString().trim();
if (!name || !email || !message) {
alert('Please fill in all required fields.');
return;
}
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
alert('Please enter a valid email address.');
return;
}
const submitButton = this.querySelector('button[type="submit"]');
const originalText = submitButton.textContent;
submitButton.textContent = 'Sending...';
submitButton.disabled = true;
try {
// Put business info into the message so it’s not lost
const fullMessage =
message +
(business ? `\n\nBusiness: ${business}` : '');
const { error } = await supabase
.from('contact_leads')
.insert([{
name,
email,
phone: null, // you don't have a phone field on the form yet
message: fullMessage,
source: 'contact_form', // where it came from
}]);
if (error) {
console.error(error);
alert('Sorry, something went wrong sending your message. Please try again.');
} else {
alert(
`Thank you, ${name}! We've received your message and will be in touch within 24 hours to discuss your business goals and transformation opportunities.`
);
this.reset();
document.getElementById('contact').scrollIntoView({ behavior: 'smooth' });
}
} catch (err) {
console.error(err);
alert('Unexpected error. Please try again.');
} finally {
submitButton.textContent = originalText;
submitButton.disabled = false;
}
});
}
// ---- Download / Accelerator signup form (sends to newsletter_subscribers) ----
const downloadForm = document.getElementById('downloadGuideForm');
if (downloadForm) {
downloadForm.addEventListener('submit', async function (e) {
e.preventDefault();
const emailInput = this.querySelector('input[name="download_email"]');
const email = emailInput.value.trim();
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
alert('Please enter a valid email address.');
return;
}
const submitButton = this.querySelector('button[type="submit"]');
const originalText = submitButton.textContent;
submitButton.textContent = 'Sending...';
submitButton.disabled = true;
try {
const { error } = await supabase
.from('newsletter_subscribers')
.insert([{
email,
source: 'accelerator_signup'
}]);
if (error) {
// If it's a duplicate email, treat as success so the user isn't confused
if (error.code === '23505') {
alert(`You're already signed up! Updates will continue to go to ${email}.`);
} else {
console.error(error);
alert('Sorry, something went wrong. Please try again.');
}
} else {
alert(`Thank you! Our updates will be sent to ${email} shortly.`);
this.reset();
}
} catch (err) {
console.error(err);
alert('Unexpected error. Please try again.');
} finally {
submitButton.textContent = originalText;
submitButton.disabled = false;
}
});
}
// ---- Navbar scroll effect ----
window.addEventListener('scroll', function () {
const navbar = document.querySelector('.navbar');
if (!navbar) return;
if (window.scrollY > 100) {
navbar.style.backgroundColor = 'rgba(255, 255, 255, 0.95)';
navbar.style.backdropFilter = 'blur(10px)';
} else {
navbar.style.backgroundColor = '#ffffff';
navbar.style.backdropFilter = 'none';
}
});
// ---- Intersection Observer for animations ----
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
document.addEventListener('DOMContentLoaded', function () {
const animatedElements = document.querySelectorAll('.value-card, .partner-card, .service-card');
animatedElements.forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(30px)';
el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(el);
});
});
// ---- Butterfly animation enhancement ----
document.addEventListener('DOMContentLoaded', function () {
const butterflies = document.querySelectorAll('.butterfly');
butterflies.forEach((butterfly, index) => {
setInterval(() => {
const randomX = Math.random() * 20 - 10;
const randomY = Math.random() * 20 - 10;
butterfly.style.transform = `translate(${randomX}px, ${randomY}px)`;
}, 3000 + index * 1000);
});
});
// ---- CTA button click animation ----
document.addEventListener('DOMContentLoaded', function () {
const ctaButtons = document.querySelectorAll('.btn-primary');
ctaButtons.forEach(button => {
button.addEventListener('click', function () {
this.style.transform = 'scale(0.95)';
setTimeout(() => {
this.style.transform = 'scale(1)';
}, 150);
});
});
});
// ---- Form field focus effects ----
document.addEventListener('DOMContentLoaded', function () {
const formInputs = document.querySelectorAll('input, textarea');
formInputs.forEach(input => {
input.addEventListener('focus', function () {
if (this.parentElement) {
this.parentElement.classList.add('focused');
}
});
input.addEventListener('blur', function () {
if (!this.value && this.parentElement) {
this.parentElement.classList.remove('focused');
}
});
});
});