generated from vexxdz911/www.vexdz.bio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerch.js
161 lines (144 loc) · 5.5 KB
/
merch.js
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
// Shopping Cart Functionality
class ShoppingCart {
constructor() {
this.items = [];
this.initializeCart();
this.bindEvents();
}
initializeCart() {
// Load cart from localStorage if available
const savedCart = localStorage.getItem('cart');
if (savedCart) {
this.items = JSON.parse(savedCart);
this.updateCartBadge();
}
}
bindEvents() {
// Add to cart buttons
document.querySelectorAll('.add-to-cart').forEach(button => {
button.addEventListener('click', (e) => {
const card = e.target.closest('.product-card');
const product = {
id: Date.now(), // Temporary ID
name: card.querySelector('h3').textContent,
price: parseFloat(card.querySelector('.price').textContent.replace('$', '')),
image: card.querySelector('img').src
};
this.addItem(product);
this.showNotification('Added to cart!');
});
});
// Quick view buttons
document.querySelectorAll('.quick-view').forEach(button => {
button.addEventListener('click', (e) => {
const card = e.target.closest('.product-card');
this.showQuickView(card);
});
});
}
addItem(product) {
this.items.push(product);
this.saveCart();
this.updateCartBadge();
}
removeItem(productId) {
this.items = this.items.filter(item => item.id !== productId);
this.saveCart();
this.updateCartBadge();
}
saveCart() {
localStorage.setItem('cart', JSON.stringify(this.items));
}
updateCartBadge() {
const badge = document.querySelector('.cart-badge');
if (badge) {
badge.setAttribute('data-count', this.items.length);
}
}
showNotification(message) {
const notification = document.createElement('div');
notification.className = 'notification';
notification.textContent = message;
document.body.appendChild(notification);
// Trigger animation
setTimeout(() => notification.classList.add('show'), 100);
setTimeout(() => {
notification.classList.remove('show');
setTimeout(() => notification.remove(), 300);
}, 2000);
}
showQuickView(productCard) {
const modal = document.createElement('div');
modal.className = 'quick-view-modal';
modal.innerHTML = `
<div class="modal-content">
<button class="close-modal">×</button>
<div class="modal-body">
<div class="product-image">
<img src="${productCard.querySelector('img').src}" alt="Product">
</div>
<div class="product-details">
<h3>${productCard.querySelector('h3').textContent}</h3>
<p class="price">${productCard.querySelector('.price').textContent}</p>
<div class="product-meta">
${productCard.querySelector('.product-meta').innerHTML}
</div>
<button class="btn-primary add-to-cart">Add to Cart</button>
</div>
</div>
</div>
`;
document.body.appendChild(modal);
setTimeout(() => modal.classList.add('show'), 100);
// Close modal functionality
const closeBtn = modal.querySelector('.close-modal');
closeBtn.addEventListener('click', () => {
modal.classList.remove('show');
setTimeout(() => modal.remove(), 300);
});
// Add to cart from modal
modal.querySelector('.add-to-cart').addEventListener('click', () => {
const product = {
id: Date.now(),
name: productCard.querySelector('h3').textContent,
price: parseFloat(productCard.querySelector('.price').textContent.replace('$', '')),
image: productCard.querySelector('img').src
};
this.addItem(product);
this.showNotification('Added to cart!');
modal.classList.remove('show');
setTimeout(() => modal.remove(), 300);
});
}
}
// Newsletter Form
function initializeNewsletterForm() {
const form = document.querySelector('.newsletter-form');
if (form) {
form.addEventListener('submit', (e) => {
e.preventDefault();
const email = form.querySelector('input[type="email"]').value;
// Add newsletter subscription logic here
showNotification('Thanks for subscribing! Check your email for the discount code.');
form.reset();
});
}
}
// Mobile Menu
function initializeMobileMenu() {
const mobileMenuBtn = document.querySelector('.mobile-menu');
const navLinks = document.querySelector('.nav-links');
if (mobileMenuBtn && navLinks) {
mobileMenuBtn.addEventListener('click', () => {
navLinks.classList.toggle('active');
mobileMenuBtn.querySelector('i').classList.toggle('fa-bars');
mobileMenuBtn.querySelector('i').classList.toggle('fa-times');
});
}
}
// Initialize everything when the page loads
document.addEventListener('DOMContentLoaded', () => {
const cart = new ShoppingCart();
initializeNewsletterForm();
initializeMobileMenu();
});