bazaarbondhu44@gmail.com 01717-282744

āĻŦāĻžāϜāĻžāϰ āĻŦāĻ¨ā§āϧ⧁

Login 0 ā§ŗ0

🛒 Products by Category (ā§ŗ1001 - ā§ŗ999999)


Home

Categories

Cart

Login
/* ====================================== 🔁 Product Slider (Horizontal Carousel) ====================================== */ const track = document.getElementById('slider-track'); const btnLeft = document.querySelector('.btn-left'); const btnRight = document.querySelector('.btn-right'); const productWidth = 170; // product width + margin let visibleProducts = Math.floor(document.querySelector('.slider-container').offsetWidth / productWidth); const totalProducts = track.children.length; let currentIndex = 0; function updateSlider() { if (currentIndex < 0) currentIndex = 0; if (currentIndex > totalProducts - visibleProducts) currentIndex = totalProducts - visibleProducts; const distance = -currentIndex * productWidth; track.style.transform = `translateX(${distance}px)`; } btnRight.addEventListener('click', () => { currentIndex++; updateSlider(); }); btnLeft.addEventListener('click', () => { currentIndex--; updateSlider(); }); setInterval(() => { currentIndex++; if (currentIndex > totalProducts - visibleProducts) { currentIndex = 0; } updateSlider(); }, 3000); // ✅ FIXED: Only reload on desktop window.addEventListener('resize', () => { if (window.innerWidth > 768) { location.reload(); // Only reload for desktop/tablet } }); /* ================================ 📂 Category Dropdown Toggle ================================ */ const categoryToggle = document.getElementById('categoryToggle'); const categoryWrapper = document.getElementById('categoryWrapper'); const toggleIcon = document.getElementById('toggleIcon'); let isOpen = false; categoryToggle.addEventListener('click', () => { isOpen = !isOpen; if (isOpen) { categoryWrapper.style.maxHeight = categoryWrapper.scrollHeight + 'px'; toggleIcon.classList.replace('fa-chevron-down', 'fa-chevron-up'); } else { categoryWrapper.style.maxHeight = '0'; toggleIcon.classList.replace('fa-chevron-up', 'fa-chevron-down'); } }); /* ================================ đŸ–ŧī¸ Banner Slider with Dots ================================ */ let slideIndex = 0; const slides = document.querySelectorAll('.mySlides'); const dots = document.querySelectorAll('.dot'); function showSlides(n) { if (n >= slides.length) slideIndex = 0; if (n < 0) slideIndex = slides.length - 1; slides.forEach((slide, i) => { slide.classList.toggle('active', i === slideIndex); }); dots.forEach((dot, i) => { dot.classList.toggle('active', i === slideIndex); }); } function nextSlide() { slideIndex++; showSlides(slideIndex); } function currentSlide(n) { slideIndex = n - 1; showSlides(slideIndex); } setInterval(nextSlide, 3000); showSlides(slideIndex); /* ================================ 🛒 Add to Cart via AJAX ================================ */ document.querySelectorAll('.add-to-cart-form').forEach(form => { form.addEventListener('submit', function (e) { e.preventDefault(); const formData = new FormData(this); fetch('add_to_cart.php', { method: 'POST', body: formData }) .then(res => res.json()) .then(data => { if (data.success) { document.getElementById('cart-count').innerText = data.cart_count; document.getElementById('cart-total').innerText = 'ā§ŗ' + data.total_price; const alertBox = document.getElementById('cart-alert'); alertBox.classList.remove('d-none'); setTimeout(() => { alertBox.classList.add('d-none'); }, 3000); } }); }); }); /* =================================== 🔍 Live Product Search Suggestions =================================== */ const liveSearch = document.getElementById('live-search'); const searchSuggestions = document.getElementById('search-suggestions'); liveSearch.addEventListener('input', function () { const query = this.value.trim(); if (query.length >= 2) { fetch(`live_search.php?term=${encodeURIComponent(query)}`) .then(res => res.json()) .then(data => { searchSuggestions.innerHTML = ''; if (data.length > 0) { data.forEach(product => { const item = document.createElement('a'); item.href = `product_details.php?id=${product.id}`; item.classList.add('list-group-item', 'list-group-item-action', 'd-flex', 'align-items-center'); item.innerHTML = ` ${product.name} `; searchSuggestions.appendChild(item); }); searchSuggestions.style.display = 'block'; } else { searchSuggestions.style.display = 'none'; } }); } else { searchSuggestions.style.display = 'none'; } }); document.addEventListener('click', function (e) { if (!liveSearch.contains(e.target)) { searchSuggestions.style.display = 'none'; } }); /* ================================ 📱 Highlight Active Mobile Menu ================================ */ const links = document.querySelectorAll('.mobile-menu-link'); const current = window.location.pathname; links.forEach(link => { if (link.getAttribute('href') && current.includes(link.getAttribute('href'))) { link.classList.add('active'); } }); /* ================================ 📱 Mobile Menu Toggle Button ================================ */ const menuBtn = document.getElementById('mobileMenuBtn'); const mobileMenu = document.getElementById('mobileMenu'); menuBtn.addEventListener('click', () => { mobileMenu.style.display = (mobileMenu.style.display === 'block') ? 'none' : 'block'; }); document.addEventListener('click', function (event) { if (!menuBtn.contains(event.target) && !mobileMenu.contains(event.target)) { mobileMenu.style.display = 'none'; } }); /* ================================ 🍔 Hamburger Menu Toggle ================================ */ document.querySelectorAll('#mobileMenu a').forEach(link => { link.addEventListener('click', () => { document.getElementById('mobileMenu').style.display = 'none'; }); }); /* ================================ 📂 Mobile Category Dropdown ================================ */