diff --git a/index.js b/index.js index 450a3e7..8b13789 100644 --- a/index.js +++ b/index.js @@ -1,322 +1 @@ -let food = []; -let totalAmount = 0; -$(document).ready(function () { - if ($(document).width() <= 992) { - $(".navbar-nav").removeClass("ml-auto"); - $(".navbar-nav").addClass("mr-auto"); - } else { - $(".navbar-nav").removeClass("mr-auto"); - $(".navbar-nav").addClass("ml-auto"); - } - - var scrollToTopBtn = $("#scrollToTop"); - - $(window).scroll(function () { - if ($(window).scrollTop() > 300) { - scrollToTopBtn.addClass("show"); - } else { - scrollToTopBtn.removeClass("show"); - } - }); - - scrollToTopBtn.on("click", function (event) { - event.preventDefault(); - $("html, body").animate( - { - scrollTop: 0, - }, - "500" - ); - }); - - $(".navbar a").on("click", function (event) { - // Make sure this.hash has a value before overriding default behavior - if (this.hash !== "") { - // console.log(this); - // console.log(this.hash); - // Prevent default anchor click behavior - event.preventDefault(); - // Store hash - var hash = this.hash; - // Using jQuery's animate() method to add smooth page scroll - // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area - $("html, body").animate( - { - scrollTop: $(hash).offset().top, - }, - 800, - function () { - // Add hash (#) to URL when done scrolling (default click behavior) - window.location.hash = hash; - } - ); - } // End if - }); - - $(".homeBtn").click(function (event) { - if (this.hash !== "") { - event.preventDefault(); - let hash = this.hash; - - $("html, body").animate( - { - scrollTop: $(hash).offset().top, - }, - 800, - function () { - // Add hash (#) to URL when done scrolling (default click behavior) - window.location.hash = hash; - } - ); - } - }); - - $(".product-box-layout4").click(function () { - $(this) - .toggleClass("productClicked") - .parent() - .siblings("div") - .children() - .removeClass("productClicked"); - if ($(this)[0].className.search("momos productClicked") > -1) { - $("#momos").show().siblings("div").hide(); - - $("html, body").animate( - { - scrollTop: $("#momos").offset().top, - }, - 800, - function () {} - ); - } else if ($(this)[0].className.search("chinese productClicked") > -1) { - $("#chinese").show().siblings("div").hide(); - - $("html, body").animate( - { - scrollTop: $("#chinese").offset().top, - }, - 800, - function () {} - ); - } else if ($(this)[0].className.search("beverages productClicked") > -1) { - $("#beverages").show().siblings("div").hide(); - - $("html, body").animate( - { - scrollTop: $("#beverages").offset().top, - }, - 800, - function () {} - ); - } - }); - - $(".menuBtn").click(function () { - let quantity = $(this).siblings(".quantity"); - let foodNameClicked = quantity - .parent() - .siblings("div") - .children() - .first() - .text() - .trim(); - let singleFoodAmount= quantity.parent().siblings("div").children().last().text(); - let numericPart = singleFoodAmount.replace(/[^\d.]/g, ''); - if (!isNaN(numericPart)) { - singleFoodAmount = parseFloat(numericPart); - } - let isVeg = quantity - .parent() - .siblings("div") - .children() - .first() - .children() - .first() - .children() - .hasClass("vegIcon"); - - let count = Number(quantity.text()); - if ($(this)[0].className.search("plus") > -1) { - count = count + 1; - quantity.text(count); - ToCart(foodNameClicked, count, isVeg, singleFoodAmount); - } else if ($(this)[0].className.search("minus") > -1) { - if (count <= 0) { - quantity.text(0); - } else { - count = count - 1; - quantity.text(count); - ToCart(foodNameClicked, count, isVeg, singleFoodAmount); - } - } - }); - - function ToCart(foodNameClicked, foodQuantity, isVeg, singleFoodAmount) { - let foodAlreadyThere = false; - let foodPos; - let node; - if (isVeg) { - node = ''; - } else { - node = ''; - } - for (var i = 0; i < food.length; i++) { - if (food[i][0] === foodNameClicked) { - foodAlreadyThere = true; - foodPos = i; - break; - } else { - foodAlreadyThere = false; - } - } - - if (foodAlreadyThere) { - food.splice(foodPos, 1); - food.push([foodNameClicked, foodQuantity, singleFoodAmount, node]); - } else { - food.push([foodNameClicked, foodQuantity, singleFoodAmount, node]); - } - - // Remove Food items with quantity = 0 - for (var i = 0; i < food.length; i++) { - if (food[i][1] === 0) { - food.splice(i, 1); - } - } - - if (food.length !== 0) { - $(".shoppingCart").addClass("shoppingCartWithItems"); - - $(".cartContentDiv").empty(); - for (var i = 0; i < food.length; i++) { - let cartTxt = - '

' + - food[i][0] + - '

' + - food[i][3] + - '

' + - food[i][2] + - '

' + - food[i][1] * food[i][2] + - '

' + - " Qty : " + - food[i][1] + - '

'; - $(".cartContentDiv").append(cartTxt); - } - } else { - $(".shoppingCart").removeClass("shoppingCartWithItems"); - - $(".cartContentDiv").empty(); - $(".cartContentDiv").append( - '

Your Cart is Empty

' - ); - } - - $(".shoppingCartAfter").text(food.length); - if (food.length === 0) { - totalAmount = 0; - }else { - totalAmount = totalAmount + singleFoodAmount; - } - $(".totalAmountDiv").empty(); - $(".totalAmountDiv").append( - 'TOTAL AMOUNT :
' + - ' ' + - totalAmount - ); - } -}); - -function openWhatsapp() { - // console.log($('#address')); - - if ($("#address")[0].value === "") { - alert("Please Enter your room number"); - return; - } else { - let total = 0; - let address = $("#address")[0].value; - let note = $("#note")[0].value; - let wTxt = "*name* *quantity* \n"; - - for (var i = 0; i < food.length; i++) { - let name = food[i][0]; - let quantity = food[i][1]; - total = total + food[i][1] * food[i][2]; - wTxt = wTxt + name + " " + quantity + " \n"; - } - - if ($("#note")[0].value === "") { - wTxt = - wTxt + "\n *Total Bill: " + total + "*" + "\n\n Address: " + address; - } else { - wTxt = - wTxt + - "\n *Total Bill: " + - total + - "*" + - "\n\n Address: " + - address + - "\n Note: " + - note; - } - - let wTxtEncoded = encodeURI(wTxt); - window.open("https://wa.me/7459943936?text=" + wTxtEncoded); - } -} - -// function openWhatsapp() { -// if ($("#address")[0].value === "") { -// alert("Please Enter your room number"); -// return; -// } else { -// let total = 0; -// let address = $("#address")[0].value; -// let note = $("#note")[0].value; -// let wTxt = "*name* *quantity* \n"; - -// for (var i = 0; i < food.length; i++) { -// let name = food[i][0]; -// let quantity = food[i][1]; -// total = total + food[i][1] * food[i][2]; -// wTxt = wTxt + name + " " + quantity + " \n"; -// } - -// if ($("#note")[0].value === "") { -// wTxt = -// wTxt + "\n *Total Bill: " + total + "*" + "\n\n Address: " + address; -// } else { -// wTxt = -// wTxt + -// "\n *Total Bill: " + -// total + -// "*" + -// "\n\n Address: " + -// address + -// "\n Note: " + -// note; -// } - -// let wTxtEncoded; -// let idValue = $("#id").val(); - -// // Situation 1: id="id1" redirect to first whatsapp number -// if (idValue === "momos") { -// wTxtEncoded = encodeURI(wTxt); -// window.open("https://wa.me/9696279459?text=" + wTxtEncoded); - -// // Situation 2: id="id2" redirect to second whatsapp number -// } else if (idValue === "chinese") { -// wTxtEncoded = encodeURI(wTxt); -// window.open("https://wa.me/955677085?text=" + wTxtEncoded); - -// // Situation 3: id="id3" redirect to third whatsapp number -// } else if (idValue === "beverages") { -// wTxtEncoded = encodeURI(wTxt); -// window.open("https://wa.me/7965306761?text=" + wTxtEncoded); -// } -// } -// }