preview/IntelliChat
0
1let currentIndex = 0,2 menu = document.querySelector(".menu-icon"),3 navbar = document.querySelector(".navbar"),4 bag = document.getElementById("bill"),5 listProductBill = [],6 checkTakeAWay = false;7 8// JavaScript for automatic slide change9const slides = document.querySelectorAll(".swiper-slide");10function showSlide1(index) {11 slides.forEach((slide, i) => {12 slide.style.display = i === index ? "block" : "none";13 });14}15function nextSlide() {16 currentIndex = (currentIndex + 1) % slides.length;17 showSlide1(currentIndex);18}19setInterval(nextSlide, 3000);20showSlide1(currentIndex);21 22// Menu open and close23menu.onclick = () => {24 menu.classList.toggle("move");25 navbar.classList.toggle("open-menu");26};27 28// Close menu29window.onscroll = () => {30 menu.classList.remove("move");31 navbar.classList.remove("open-menu");32};33 34// Open Menu Products35function goToShoppingPage() {36 window.location.href = "Products.html";37}38function goToHomePage() {39 window.location.href = "mainCoffee.html";40}41 42function MenuToTakeAWay() {43 goToShoppingPage();44 checkTakeAWay = true;45}46 47function displayBill() {48 if (bag !== null) {49 if (bag.style.width === "0%") {50 bag.style.width = "20%";51 } else {52 bag.style.width = "0%";53 }54 } else {55 console.error("Element with ID 'bill' not found.");56 }57}58 59// add products with name, images and price to the cart, display cart in the right60// Function to handle click on the heart icon61function handleHeartClick(event) {62 // Navigate up to the parent product-box element63 let productBox = event.target.closest(".product-box");64 65 if (productBox !== null) {66 // Get specific information from product-box67 let productName = productBox.querySelector("h2").textContent.trim();68 let priceRange = productBox69 .querySelector(".product-info span")70 .textContent.trim();71 let imageUrl = productBox.querySelector("img").src;72 73 let existingProduct = listProductBill.find(74 (product) => product.name === productName75 );76 if (existingProduct) {77 // If product exists, increment the quantity78 existingProduct.quantity++;79 } else {80 // Create an object with the extracted information81 let productInfo = {82 name: productName,83 price: priceRange,84 image: imageUrl,85 quantity: 1,86 };87 88 // Push the information to the list89 listProductBill.push(productInfo);90 }91 // Display the list in the console92 console.log(listProductBill);93 } else {94 console.log("Product information not found!");95 }96 renderListProduct();97}98// Attach click event listener to all heart icons with class "bx-shopping-bag"99let heartIcons = document.querySelectorAll(".bx-shopping-bag");100heartIcons.forEach((icon) => {101 icon.addEventListener("click", handleHeartClick);102});103 104// Delete products in bill105function removeProduct(productName) {106 const shouldDelete = window.confirm(107 `Do you want to remove "${productName}" from the list?`108 );109 if (shouldDelete) {110 const indexToRemove = listProductBill.findIndex(111 (product) => product.name === productName112 );113 if (indexToRemove !== -1) {114 listProductBill.splice(indexToRemove, 1);115 renderListProduct();116 } else {117 alert(`Product not found: ${productName}`);118 }119 }120}121// Total price and ask customer with cash or credit cards122function showHiddenTag() {123 var hiddenTag = document.getElementById("hiddenTag");124 document.getElementById("thankyou").style.width = "20%";125 if (checkTakeAWay === true) {126 hiddenTag.innerHTML = `<h1>Thank you so much!</h1>127 <h3>Your items will be there in a few minutes!</h3>128 <h1>$ ${totalBill}</h1>`;129 } else {130 hiddenTag.innerHTML = `<h1>Wish you a good appetite!</h1>131 <h3>Your items will be there in a few minutes!</h3>132 <h1>$ ${totalBill}</h1>`;133 }134 setTimeout(function () {135 document.getElementById("thankyou").style.width = "0%";136 }, 5000);137 displayBill();138 listProductBill = [];139 renderListProduct();140 checkTakeAWay = false;141}142 143function CheckBook() {144 let number = document.getElementById("booknumber").value;145 let name = document.getElementById("bookname").value;146 147 alert(148 `Hi ${name}, We will contact you via this number ${number} as soon as possible!`149 );150 151 // Reset input values152 document.getElementById("booknumber").value = "";153 document.getElementById("bookname").value = "";154}155 