| |
|
|
| document.addEventListener('DOMContentLoaded', function() { |
| |
| |
| |
| const addToCartButtons = document.querySelectorAll('[data-add-to-cart]'); |
| |
| addToCartButtons.forEach(button => { |
| button.addEventListener('click', function() { |
| const productId = this.getAttribute('data-product-id'); |
| |
| console.log(`Added product ${productId} to cart`); |
| |
| |
| showToast('Product added to cart!'); |
| }); |
| }); |
| |
| |
| const newsletterForm = document.querySelector('#newsletter-form'); |
| if (newsletterForm) { |
| newsletterForm.addEventListener('submit', function(e) { |
| e.preventDefault(); |
| const email = this.querySelector('input[type="email"]').value; |
| |
| console.log(`Subscribed email: ${email}`); |
| |
| |
| showToast('Thanks for subscribing! Check your email for the discount code.'); |
| this.reset(); |
| }); |
| } |
| }); |
|
|
| |
| function showToast(message) { |
| const toast = document.createElement('div'); |
| toast.className = 'fixed bottom-4 right-4 bg-gray-800 text-white px-4 py-2 rounded-lg shadow-lg animate-fade-in'; |
| toast.textContent = message; |
| document.body.appendChild(toast); |
| |
| |
| setTimeout(() => { |
| toast.classList.add('opacity-0', 'transition-opacity', 'duration-300'); |
| setTimeout(() => toast.remove(), 300); |
| }, 3000); |
| } |