-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
381 lines (310 loc) · 10.1 KB
/
Copy pathscript.js
File metadata and controls
381 lines (310 loc) · 10.1 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
// Summit Care - Main JavaScript File
document.addEventListener('DOMContentLoaded', function () {
// Initialize all components
initCarousel();
initBackToTop();
initNewsletterForm();
initFormValidation();
initThreeJS();
initRevealAnimations();
// Set current year in footer
document.getElementById('year').textContent = new Date().getFullYear();
});
// Testimonial Carousel
function initCarousel() {
const carousel = document.querySelector('.carousel');
if (!carousel) return;
const slides = carousel.querySelectorAll('.testimonial-card');
const dotsContainer = carousel.querySelector('.carousel-dots');
const prevBtn = carousel.querySelector('.carousel-btn.prev');
const nextBtn = carousel.querySelector('.carousel-btn.next');
let currentSlide = 0;
const totalSlides = slides.length;
// Create dots dynamically
if (dotsContainer) {
for (let i = 0; i < totalSlides; i++) {
const dot = document.createElement('button');
dot.className = 'carousel-dot';
dot.setAttribute('aria-label', `Go to slide ${i + 1}`);
dot.setAttribute('aria-pressed', i === 0 ? 'true' : 'false');
dotsContainer.appendChild(dot);
}
}
const dots = carousel.querySelectorAll('.carousel-dot');
function showSlide(index) {
// Hide all slides
slides.forEach((slide, i) => {
slide.style.display = i === index ? 'block' : 'none';
});
// Update dots
dots.forEach((dot, i) => {
dot.classList.toggle('active', i === index);
dot.setAttribute('aria-pressed', i === index ? 'true' : 'false');
});
currentSlide = index;
}
function nextSlide() {
showSlide((currentSlide + 1) % totalSlides);
}
function prevSlide() {
showSlide((currentSlide - 1 + totalSlides) % totalSlides);
}
// Event listeners
if (nextBtn) nextBtn.addEventListener('click', nextSlide);
if (prevBtn) prevBtn.addEventListener('click', prevSlide);
// Dot navigation
dots.forEach((dot, index) => {
dot.addEventListener('click', () => showSlide(index));
});
// Auto-advance
setInterval(nextSlide, 5000);
// Initialize first slide
showSlide(0);
}
// Back to Top Button
function initBackToTop() {
const backToTopBtn = document.getElementById('backToTop');
if (!backToTopBtn) return;
function toggleBackToTop() {
if (window.pageYOffset > 300) {
backToTopBtn.classList.add('visible');
} else {
backToTopBtn.classList.remove('visible');
}
}
function scrollToTop() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
}
window.addEventListener('scroll', toggleBackToTop);
backToTopBtn.addEventListener('click', scrollToTop);
}
// Newsletter Form
function initNewsletterForm() {
const newsletterForm = document.getElementById('newsletterForm');
if (!newsletterForm) return;
newsletterForm.addEventListener('submit', function (e) {
e.preventDefault();
const emailInput = this.querySelector('input[type="email"]');
const email = emailInput.value.trim();
if (!email) {
showToast('Please enter your email address.', 'error');
return;
}
if (!isValidEmail(email)) {
showToast('Please enter a valid email address.', 'error');
return;
}
// Show loading state
const submitBtn = this.querySelector('.newsletter-btn');
const originalHTML = submitBtn.innerHTML;
submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i>';
submitBtn.disabled = true;
// Simulate subscription
setTimeout(() => {
showToast('Thank you for subscribing to our newsletter!', 'success');
emailInput.value = '';
submitBtn.innerHTML = originalHTML;
submitBtn.disabled = false;
}, 1500);
});
}
// Form Validation
function initFormValidation() {
const contactForm = document.getElementById('contactForm');
if (!contactForm) return;
contactForm.addEventListener('submit', function (e) {
e.preventDefault();
const formData = new FormData(this);
const name = formData.get('name').trim();
const email = formData.get('email').trim();
const message = formData.get('message').trim();
let isValid = true;
let errorMessage = '';
if (!name) {
errorMessage = 'Please enter your name.';
isValid = false;
} else if (!email) {
errorMessage = 'Please enter your email address.';
isValid = false;
} else if (!isValidEmail(email)) {
errorMessage = 'Please enter a valid email address.';
isValid = false;
} else if (!message) {
errorMessage = 'Please enter your message.';
isValid = false;
}
if (!isValid) {
showToast(errorMessage, 'error');
return;
}
// Show success message
showToast('Thank you for your message! We\'ll get back to you soon.', 'success');
this.reset();
});
}
// Three.js Background Animation
function initThreeJS() {
const canvas = document.getElementById('heroCanvas');
if (!canvas) return;
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({ canvas: canvas, alpha: true, antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
// Create particles
const particlesGeometry = new THREE.BufferGeometry();
const particlesCount = 100;
const posArray = new Float32Array(particlesCount * 3);
for (let i = 0; i < particlesCount * 3; i++) {
posArray[i] = (Math.random() - 0.5) * 10;
}
particlesGeometry.setAttribute('position', new THREE.BufferAttribute(posArray, 3));
const particlesMaterial = new THREE.PointsMaterial({
size: 0.005,
color: 0x87CEEB,
transparent: true,
opacity: 0.8
});
const particlesMesh = new THREE.Points(particlesGeometry, particlesMaterial);
scene.add(particlesMesh);
// Create geometric shapes
const geometry = new THREE.IcosahedronGeometry(0.5, 0);
const material = new THREE.MeshBasicMaterial({
color: 0x90EE90,
wireframe: true,
transparent: true,
opacity: 0.3
});
const shapes = [];
for (let i = 0; i < 5; i++) {
const shape = new THREE.Mesh(geometry, material);
shape.position.set(
(Math.random() - 0.5) * 8,
(Math.random() - 0.5) * 8,
(Math.random() - 0.5) * 8
);
shape.rotation.set(
Math.random() * Math.PI,
Math.random() * Math.PI,
Math.random() * Math.PI
);
shapes.push(shape);
scene.add(shape);
}
camera.position.z = 5;
// Animation loop
function animate() {
requestAnimationFrame(animate);
particlesMesh.rotation.y += 0.001;
particlesMesh.rotation.x += 0.0005;
shapes.forEach((shape, index) => {
shape.rotation.x += 0.01 + index * 0.001;
shape.rotation.y += 0.01 + index * 0.001;
});
renderer.render(scene, camera);
}
animate();
// Handle window resize
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener('resize', onWindowResize);
}
// Reveal Animations on Scroll
function initRevealAnimations() {
const revealElements = document.querySelectorAll('.reveal-up');
if (revealElements.length === 0) {
console.log('No reveal-up elements found');
return;
}
console.log(`Found ${revealElements.length} reveal-up elements`);
// Add animated class to enable animations
revealElements.forEach(element => {
element.classList.add('animated');
});
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('in-view');
console.log('Element in view:', entry.target);
// Unobserve after animation to improve performance
observer.unobserve(entry.target);
}
});
}, observerOptions);
revealElements.forEach(element => {
observer.observe(element);
// For debugging: show elements immediately on mobile
if (window.innerWidth < 768) {
element.classList.add('in-view');
}
});
// Fallback: show all elements after a delay if they're still hidden
setTimeout(() => {
revealElements.forEach(element => {
if (!element.classList.contains('in-view')) {
element.classList.add('in-view');
console.log('Fallback: showing element:', element);
}
});
}, 2000);
}
// Utility Functions
function isValidEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
// Toast Notification System
function showToast(message, type = 'info') {
let toast = document.createElement('div');
toast.setAttribute('role', 'status');
toast.setAttribute('aria-live', 'polite');
const colors = {
info: { bg: 'rgba(135, 206, 235, 0.95)', color: '#00324a' },
success: { bg: 'rgba(144, 238, 144, 0.95)', color: '#054105' },
warning: { bg: 'rgba(255, 193, 7, 0.95)', color: '#856404' },
error: { bg: 'rgba(220, 53, 69, 0.95)', color: '#ffffff' }
};
const style = colors[type] || colors.info;
toast.style.cssText = `
position: fixed;
left: 50%;
bottom: 32px;
transform: translateX(-50%);
background: ${style.bg};
color: ${style.color};
padding: 16px 24px;
border-radius: 16px;
box-shadow: 0 8px 32px rgba(0,0,0,0.2);
z-index: 9999;
font-weight: 500;
max-width: 90vw;
text-align: center;
backdrop-filter: blur(8px);
`;
toast.textContent = message;
document.body.appendChild(toast);
// Animate in
toast.style.opacity = '0';
toast.style.transform = 'translateX(-50%) translateY(20px)';
toast.style.transition = 'all 300ms ease-out';
setTimeout(() => {
toast.style.opacity = '1';
toast.style.transform = 'translateX(-50%) translateY(0)';
}, 10);
// Remove after delay
setTimeout(() => {
toast.style.opacity = '0';
toast.style.transform = 'translateX(-50%) translateY(20px)';
setTimeout(() => toast.remove(), 300);
}, 4000);
}