File size: 1,857 Bytes
23ecbaa | 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 | // Main JavaScript file for Cata Commerce Explorer
document.addEventListener('DOMContentLoaded', function() {
// Initialize any global functionality here
// Example: Add to cart functionality
const addToCartButtons = document.querySelectorAll('[data-add-to-cart]');
addToCartButtons.forEach(button => {
button.addEventListener('click', function() {
const productId = this.getAttribute('data-product-id');
// In a real app, you would add the product to cart here
console.log(`Added product ${productId} to cart`);
// Show a temporary notification
showToast('Product added to cart!');
});
});
// Newsletter form submission
const newsletterForm = document.querySelector('#newsletter-form');
if (newsletterForm) {
newsletterForm.addEventListener('submit', function(e) {
e.preventDefault();
const email = this.querySelector('input[type="email"]').value;
// In a real app, you would send this to your backend
console.log(`Subscribed email: ${email}`);
// Show a temporary notification
showToast('Thanks for subscribing! Check your email for the discount code.');
this.reset();
});
}
});
// Helper function to show toast notifications
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);
// Remove toast after 3 seconds
setTimeout(() => {
toast.classList.add('opacity-0', 'transition-opacity', 'duration-300');
setTimeout(() => toast.remove(), 300);
}, 3000);
} |