bsatishebox/bookworm-s-paradise
0
1document.addEventListener('DOMContentLoaded', function() {2 // Initialize cart functionality3 const addToCartButtons = document.querySelectorAll('.add-to-cart');4 5 addToCartButtons.forEach(button => {6 button.addEventListener('click', function() {7 const bookTitle = this.getAttribute('data-title');8 const bookPrice = this.getAttribute('data-price');9 10 // In a real app, you would add to cart logic here11 console.log(`Added ${bookTitle} to cart for $${bookPrice}`);12 13 // Show notification14 showNotification(`${bookTitle} added to cart!`);15 });16 });17 18 // Notification function19 function showNotification(message) {20 const notification = document.createElement('div');21 notification.className = 'fixed bottom-4 right-4 bg-green-500 text-white px-4 py-2 rounded-lg shadow-lg flex items-center';22 notification.innerHTML = `23 <i data-feather="check-circle" class="mr-2"></i>24 <span>${message}</span>25 `;26 document.body.appendChild(notification);27 feather.replace();28 29 // Remove after 3 seconds30 setTimeout(() => {31 notification.classList.add('opacity-0', 'transition-opacity', 'duration-300');32 setTimeout(() => notification.remove(), 300);33 }, 3000);34 }35 36 // Search functionality37 const searchInput = document.querySelector('#search-input');38 if (searchInput) {39 searchInput.addEventListener('input', function() {40 const searchTerm = this.value.toLowerCase();41 const bookCards = document.querySelectorAll('custom-book-card');42 43 bookCards.forEach(card => {44 const title = card.getAttribute('title').toLowerCase();45 const author = card.getAttribute('author').toLowerCase();46 47 if (title.includes(searchTerm) || author.includes(searchTerm)) {48 card.style.display = 'block';49 } else {50 card.style.display = 'none';51 }52 });53 });54 }55});