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][1] * food[i][2] + - '
' + - " Qty : " + - food[i][1] + - '