-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
194 lines (173 loc) · 6.09 KB
/
script.js
File metadata and controls
194 lines (173 loc) · 6.09 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
// --- Carousel Logic for Importing Captions Section ---
document.addEventListener('DOMContentLoaded', () => {
const carouselSection = document.getElementById('feature-solutions');
if (carouselSection) {
const cards = carouselSection.querySelectorAll('.carousel-card');
const videos = carouselSection.querySelectorAll('.feature-video');
const tabs = carouselSection.querySelectorAll('.carousel-tab');
let activeIdx = 0;
let carouselTimer = null;
function updateCarousel(resetTimer = true) {
cards.forEach((card, idx) => {
card.classList.remove('active', 'left', 'right');
if (idx === activeIdx) {
card.classList.add('active');
card.style.pointerEvents = 'auto'; // Allow clicks on active card
} else if (idx === (activeIdx + 1) % 3) {
card.classList.add('right');
card.style.pointerEvents = 'none'; // Disable clicks on side cards
} else if (idx === (activeIdx + 2) % 3) {
card.classList.add('left');
card.style.pointerEvents = 'none'; // Disable clicks on side cards
} else {
card.style.pointerEvents = 'none'; // Disable clicks on other cards
}
});
tabs.forEach((tab, idx) => {
tab.classList.toggle('active', idx === activeIdx);
});
videos.forEach((video, idx) => {
if (idx === activeIdx) {
video.currentTime = 0;
video.play();
} else {
video.pause();
video.currentTime = 0;
}
});
if (resetTimer) {
resetCarouselTimer();
}
}
function resetCarouselTimer() {
if (carouselTimer) clearInterval(carouselTimer);
carouselTimer = setInterval(() => {
activeIdx = (activeIdx + 1) % 3;
updateCarousel(false);
}, 10000);
}
// Handle card clicks for navigation
cards.forEach((card, idx) => {
card.addEventListener('click', (e) => {
e.stopPropagation(); // Prevent event from bubbling up
// If clicking on a non-active card, go directly to that card
if (idx !== activeIdx) {
activeIdx = idx;
updateCarousel();
return;
}
// If clicking on active card, check click position for navigation
const rect = card.getBoundingClientRect();
const clickX = e.clientX - rect.left;
const cardWidth = rect.width;
const zoneWidth = cardWidth * 0.4; // 40% of card width on each side
if (clickX < zoneWidth) {
// Clicked on left side - go to previous
activeIdx = (activeIdx + 2) % 3;
} else if (clickX > (cardWidth - zoneWidth)) {
// Clicked on right side - go to next
activeIdx = (activeIdx + 1) % 3;
} else {
// Clicked in middle - do nothing
return;
}
updateCarousel();
});
});
tabs.forEach((tab, idx) => {
tab.addEventListener('click', () => {
if (idx !== activeIdx) {
activeIdx = idx;
updateCarousel();
}
});
});
document.addEventListener('keydown', e => {
if (!carouselSection.contains(document.activeElement)) return;
if (e.key === 'ArrowLeft') {
activeIdx = (activeIdx + 2) % 3;
updateCarousel();
} else if (e.key === 'ArrowRight') {
activeIdx = (activeIdx + 1) % 3;
updateCarousel();
}
});
// Add click handlers for navigation overlays
const leftNav = carouselSection.querySelector('.left-nav');
const rightNav = carouselSection.querySelector('.right-nav');
const navigateLeft = (e) => {
e.stopPropagation();
activeIdx = (activeIdx + 2) % 3; // Go to previous
updateCarousel();
};
const navigateRight = (e) => {
e.stopPropagation();
activeIdx = (activeIdx + 1) % 3; // Go to next
updateCarousel();
};
if (leftNav) {
leftNav.addEventListener('click', navigateLeft);
}
if (rightNav) {
rightNav.addEventListener('click', navigateRight);
}
// Also allow clicking on the side cards to navigate
cards.forEach((card, idx) => {
card.addEventListener('click', (e) => {
if (card.classList.contains('left')) {
navigateLeft(e);
} else if (card.classList.contains('right')) {
navigateRight(e);
} else if (card.classList.contains('active')) {
// Handle click on active card if needed
e.stopPropagation();
}
});
});
// Start the timer and initialize
updateCarousel();
}
});
// --- Modal Functionality ---
document.addEventListener('DOMContentLoaded', () => {
const modal = document.getElementById('subscribe-modal');
const openBtn = document.getElementById('open-subscribe-modal');
const closeBtn = document.getElementById('close-subscribe-modal');
// Function to open the modal
const openModal = () => {
if (modal) {
modal.style.display = 'block';
document.body.classList.add('modal-open'); // Prevent background scroll
}
};
// Function to close the modal
const closeModal = () => {
if (modal) {
modal.style.display = 'none';
document.body.classList.remove('modal-open'); // Allow background scroll
}
};
// Event listener for the open button
if (openBtn) {
openBtn.addEventListener('click', openModal);
}
// Event listener for the close button
if (closeBtn) {
closeBtn.addEventListener('click', closeModal);
}
// Event listener to close modal if clicked outside the content
if (modal) {
modal.addEventListener('click', (event) => {
// Check if the click is directly on the modal background (not the content)
if (event.target === modal) {
closeModal();
}
});
}
// Optional: Close modal with the Escape key
document.addEventListener('keydown', (event) => {
if (event.key === 'Escape' && modal && modal.style.display === 'block') {
closeModal();
}
});
});