Spaces:
Running
Running
| // Initialize cart functionality | |
| document.addEventListener('DOMContentLoaded', () => { | |
| const cart = []; | |
| // Listen for add to cart events from coffee cards | |
| document.addEventListener('add-to-cart', (e) => { | |
| const { name, price } = e.detail; | |
| cart.push({ name, price }); | |
| updateCartCount(); | |
| showToast(`${name} added to cart!`); | |
| }); | |
| function updateCartCount() { | |
| const cartCount = document.getElementById('cart-count'); | |
| if (cartCount) { | |
| cartCount.textContent = cart.length; | |
| cartCount.classList.toggle('hidden', cart.length === 0); | |
| } | |
| } | |
| function showToast(message) { | |
| const toast = document.createElement('div'); | |
| toast.className = 'fixed bottom-4 right-4 bg-amber-700 text-white px-4 py-2 rounded-lg shadow-lg'; | |
| toast.textContent = message; | |
| document.body.appendChild(toast); | |
| setTimeout(() => { | |
| toast.classList.add('opacity-0', 'transition-opacity', 'duration-300'); | |
| setTimeout(() => toast.remove(), 300); | |
| }, 2000); | |
| } | |
| }); |