-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
146 lines (130 loc) · 5.58 KB
/
Copy pathmain.js
File metadata and controls
146 lines (130 loc) · 5.58 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
document.addEventListener('DOMContentLoaded', () => {
// 1. Sticky Header
const header = document.querySelector('.header');
if (header) {
window.addEventListener('scroll', () => {
header.classList.toggle('scrolled', window.scrollY > 60);
});
}
// 2. Mobile menu toggle
const mobileBtn = document.querySelector('.mobile-menu-btn');
const navLinks = document.querySelector('.nav-links');
if (mobileBtn && navLinks) {
mobileBtn.addEventListener('click', () => navLinks.classList.toggle('active'));
}
// 3. Testimonial Slider
const track = document.querySelector('.testi-track');
const dots = document.querySelectorAll('.testi-dot');
let currentTesti = 0;
let testiInterval;
function showTesti(index) {
if (!track) return;
const slides = track.querySelectorAll('.testi-slide');
currentTesti = (index + slides.length) % slides.length;
track.style.transform = `translateX(-${currentTesti * 100}%)`;
dots.forEach((d, i) => d.classList.toggle('active', i === currentTesti));
}
function startTesti() {
stopTesti();
testiInterval = setInterval(() => showTesti(currentTesti + 1), 5000);
}
function stopTesti() { clearInterval(testiInterval); }
if (track) {
showTesti(0);
startTesti();
dots.forEach((dot, i) => dot.addEventListener('click', () => { showTesti(i); startTesti(); }));
}
// 4. Wishlist toggle
document.querySelectorAll('.wishlist-btn').forEach(btn => {
btn.addEventListener('click', (e) => {
e.preventDefault();
btn.classList.toggle('active');
});
});
// 5. Cart counter simulation
const cartCount = document.querySelector('.cart-count');
let cartQty = parseInt(localStorage.getItem('velomix_cart') || '0');
if (cartCount) cartCount.textContent = cartQty;
document.querySelectorAll('.product-quick-add, .add-to-cart-btn').forEach(btn => {
btn.addEventListener('click', (e) => {
e.preventDefault();
cartQty++;
localStorage.setItem('velomix_cart', cartQty);
if (cartCount) {
cartCount.textContent = cartQty;
cartCount.style.transform = 'scale(1.5)';
setTimeout(() => cartCount.style.transform = 'scale(1)', 300);
}
});
});
// 6. Newsletter form
const newsletterForm = document.querySelector('.newsletter-form');
if (newsletterForm) {
newsletterForm.addEventListener('submit', (e) => {
e.preventDefault();
const email = newsletterForm.querySelector('input[type=email]');
if (email && email.value) {
const subs = JSON.parse(localStorage.getItem('velomix_subs') || '[]');
subs.push({ email: email.value, date: new Date().toISOString() });
localStorage.setItem('velomix_subs', JSON.stringify(subs));
alert('Thank you for subscribing! Exclusive deals are on their way.');
email.value = '';
}
});
}
// 7. Coupon code copy
const couponCopy = document.querySelector('.coupon-copy');
const couponCode = document.querySelector('.coupon-code');
if (couponCopy && couponCode) {
couponCopy.addEventListener('click', () => {
navigator.clipboard.writeText(couponCode.textContent.trim()).then(() => {
couponCopy.textContent = 'Copied!';
setTimeout(() => couponCopy.textContent = 'Copy', 2000);
}).catch(() => {
alert('Code: ' + couponCode.textContent.trim());
});
});
}
// 8. FAQ Accordion (for contact page)
document.querySelectorAll('.faq-header').forEach(header => {
header.addEventListener('click', () => {
const item = header.parentElement;
const content = item.querySelector('.faq-content');
const icon = header.querySelector('.faq-icon');
const isOpen = item.classList.contains('active');
document.querySelectorAll('.faq-item').forEach(i => {
i.classList.remove('active');
const c = i.querySelector('.faq-content');
const ic = i.querySelector('.faq-icon');
if (c) c.style.maxHeight = null;
if (ic) ic.textContent = '+';
});
if (!isOpen) {
item.classList.add('active');
if (content) content.style.maxHeight = content.scrollHeight + 'px';
if (icon) icon.textContent = '−';
}
});
});
// 9. Size selector (product detail)
document.querySelectorAll('.size-btn').forEach(btn => {
btn.addEventListener('click', () => {
const group = btn.closest('.size-group');
if (group) group.querySelectorAll('.size-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
});
});
// 10. Contact form
const contactForm = document.getElementById('contactForm');
if (contactForm) {
contactForm.addEventListener('submit', (e) => {
e.preventDefault();
const data = Object.fromEntries(new FormData(contactForm));
const msgs = JSON.parse(localStorage.getItem('velomix_msgs') || '[]');
msgs.push({ ...data, ts: new Date().toISOString() });
localStorage.setItem('velomix_msgs', JSON.stringify(msgs));
alert('Your message has been sent! We respond within 24 hours.');
contactForm.reset();
});
}
});