-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
347 lines (299 loc) · 11.2 KB
/
script.js
File metadata and controls
347 lines (299 loc) · 11.2 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
// TAK12 Landing Page JavaScript
document.addEventListener('DOMContentLoaded', function() {
// Smooth scrolling for navigation links
const navLinks = document.querySelectorAll('a[href^="#"]');
navLinks.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetElement = document.querySelector(targetId);
if (targetElement) {
const offsetTop = targetElement.offsetTop - 80;
window.scrollTo({
top: offsetTop,
behavior: 'smooth'
});
}
});
});
// Promo code copy functionality
const promoCodes = document.querySelectorAll('.promo-code, .promo-code-large');
promoCodes.forEach(code => {
code.addEventListener('click', function() {
// Copy to clipboard
navigator.clipboard.writeText('DSMANHTUAN').then(() => {
// Show feedback
const originalText = this.textContent;
this.textContent = 'Copied!';
this.style.background = '#6B8E4D';
setTimeout(() => {
this.textContent = originalText;
this.style.background = '';
}, 1500);
}).catch(() => {
// Fallback for older browsers
alert('Promo code: DSMANHTUAN');
});
});
// Add cursor pointer
code.style.cursor = 'pointer';
code.title = 'Click to copy promo code';
});
// Animate progress bars when they come into view
const progressBars = document.querySelectorAll('.progress-fill');
const animateProgressBars = () => {
progressBars.forEach(bar => {
const rect = bar.getBoundingClientRect();
if (rect.top < window.innerHeight && rect.bottom > 0) {
const width = bar.style.width;
bar.style.width = '0%';
setTimeout(() => {
bar.style.width = width;
}, 500);
}
});
};
// 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);
// Observe elements for fade-in animation
const animatedElements = document.querySelectorAll('.benefit-card, .course-card, .testimonial-card, .video-wrapper, .video-description, .faq-item');
animatedElements.forEach((el, index) => {
el.style.opacity = '0';
el.style.transform = 'translateY(30px)';
el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
// Add staggered delay for FAQ items
if (el.classList.contains('faq-item')) {
const faqIndex = Array.from(document.querySelectorAll('.faq-item')).indexOf(el);
el.style.transitionDelay = `${faqIndex * 0.1}s`;
}
observer.observe(el);
});
// Trigger progress bar animation on scroll
window.addEventListener('scroll', animateProgressBars);
animateProgressBars(); // Initial check
// Add click tracking for analytics
const trackClick = (element, action) => {
console.log(`Tracking: ${action} clicked`);
// Send event to PostHog
if (window.posthog) {
const properties = {
button_text: element.textContent.trim(),
button_class: element.className,
page_url: window.location.href,
action: action
};
// Add course-specific data if available
const href = element.getAttribute('href');
if (href && href.includes('tak12.com/license/ex/')) {
const courseId = href.match(/ex\/(\d+\/\d+)/)?.[1];
if (courseId) {
properties.course_id = courseId;
}
}
posthog.capture('cta_clicked', properties);
}
};
// Track CTA button clicks
const ctaButtons = document.querySelectorAll('.primary-button, .cta-button, .course-cta-button, .select-course');
ctaButtons.forEach(button => {
button.addEventListener('click', () => {
trackClick(button, 'CTA Button');
});
});
// Add promo code highlight effect on scroll
let promoHighlighted = false;
const promoBox = document.querySelector('.promo-box');
window.addEventListener('scroll', () => {
if (!promoHighlighted && window.scrollY > 200) {
promoBox.style.animation = 'pulse 1s ease-in-out';
promoHighlighted = true;
setTimeout(() => {
promoBox.style.animation = '';
}, 1000);
}
});
// Mobile menu toggle (for future implementation)
const createMobileMenu = () => {
if (window.innerWidth <= 768) {
const nav = document.querySelector('.nav-links');
if (nav && !document.querySelector('.mobile-menu-toggle')) {
const toggleButton = document.createElement('button');
toggleButton.className = 'mobile-menu-toggle';
toggleButton.innerHTML = '☰';
toggleButton.style.cssText = `
background: none;
border: none;
font-size: 1.5rem;
color: var(--sage-primary);
cursor: pointer;
`;
document.querySelector('.nav-container').appendChild(toggleButton);
toggleButton.addEventListener('click', () => {
nav.style.display = nav.style.display === 'flex' ? 'none' : 'flex';
});
}
}
};
// Initialize mobile menu
createMobileMenu();
window.addEventListener('resize', createMobileMenu);
// Add discount calculator
const addDiscountCalculator = () => {
const originalPrices = document.querySelectorAll('.original-price');
const discountedPrices = document.querySelectorAll('.discounted-price');
// Apply 10% discount calculation
originalPrices.forEach((original, index) => {
const priceText = original.textContent.replace(/[^\d]/g, '');
const originalPrice = parseInt(priceText);
const discountedPrice = Math.round(originalPrice * 0.9);
if (discountedPrices[index]) {
const currency = original.textContent.includes('VND') ? ' VND' : '';
discountedPrices[index].textContent = discountedPrice.toLocaleString() + currency;
}
});
};
// Initialize discount calculator
addDiscountCalculator();
});
// Course Catalog Modal Functions
function toggleCourseCatalog() {
const modal = document.getElementById('courseCatalogModal');
if (modal.classList.contains('active')) {
modal.classList.remove('active');
document.body.style.overflow = '';
} else {
modal.classList.add('active');
document.body.style.overflow = 'hidden';
}
}
function showCategory(categoryId) {
// Hide all tab contents
const tabContents = document.querySelectorAll('.tab-content');
tabContents.forEach(content => {
content.classList.remove('active');
});
// Remove active class from all tab buttons
const tabButtons = document.querySelectorAll('.tab-btn');
tabButtons.forEach(button => {
button.classList.remove('active');
});
// Show selected tab content
const selectedContent = document.getElementById(categoryId);
if (selectedContent) {
selectedContent.classList.add('active');
}
// Add active class to clicked button
const clickedButton = event.target;
if (clickedButton) {
clickedButton.classList.add('active');
}
}
// Close modal when clicking outside
document.addEventListener('DOMContentLoaded', function() {
const modal = document.getElementById('courseCatalogModal');
if (modal) {
modal.addEventListener('click', function(e) {
if (e.target === modal) {
toggleCourseCatalog();
}
});
}
// Close modal with Escape key
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
const modal = document.getElementById('courseCatalogModal');
if (modal && modal.classList.contains('active')) {
toggleCourseCatalog();
}
}
});
});
// Add CSS animation keyframes dynamically
const style = document.createElement('style');
style.textContent = `
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.05); }
100% { transform: scale(1); }
}
.promo-code:hover,
.promo-code-large:hover {
transform: scale(1.05);
transition: transform 0.2s ease;
}
.mobile-menu-toggle {
display: none;
}
@media (max-width: 768px) {
.mobile-menu-toggle {
display: block !important;
}
.nav-links {
position: absolute;
top: 100%;
left: 0;
right: 0;
background: white;
flex-direction: column;
padding: 1rem;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
display: none;
}
.nav-links.active {
display: flex;
}
}
`;
document.head.appendChild(style);
// FAQ Toggle Functionality
function toggleFAQ(button) {
const faqItem = button.parentElement;
const faqAnswer = faqItem.querySelector('.faq-answer');
const isActive = faqItem.classList.contains('active');
// Close all other FAQ items
document.querySelectorAll('.faq-item').forEach(item => {
if (item !== faqItem) {
item.classList.remove('active');
}
});
// Toggle current FAQ item
if (isActive) {
faqItem.classList.remove('active');
} else {
faqItem.classList.add('active');
// Smooth scroll to the FAQ item if it's not fully visible
setTimeout(() => {
const rect = faqItem.getBoundingClientRect();
const windowHeight = window.innerHeight;
if (rect.bottom > windowHeight) {
faqItem.scrollIntoView({
behavior: 'smooth',
block: 'center'
});
}
}, 300);
}
}
// Keyboard accessibility for FAQ
document.addEventListener('DOMContentLoaded', function() {
const faqQuestions = document.querySelectorAll('.faq-question');
faqQuestions.forEach(question => {
question.addEventListener('keydown', function(e) {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
toggleFAQ(this);
}
});
});
});