/*jshint esversion: 6 */ let subsClicked = false; $('.code-color span').each(function () { $(this).css({ "background": $(this).text() }).text(""); }); $(document).ready(function () { // ! Slide Show let slideIndex = 1; let slides = $(".mySlides"); let dots = $(".dot"); showSlides(slideIndex); $(document).on("click", '.next', function () { showSlides(slideIndex += 1); }); $(document).on("click", '.prev', function () { showSlides(slideIndex -= 1); }); $(document).on("click", '.dot', function () { showSlides(slideIndex = parseInt($(this).attr('class').split(' ')[1])); }); function showSlides(n) { $('.magnify').hide(); if ($(".slideshow-container .mySlides").length > 0) { if (n === undefined && $(".product_page").length === 0) { return showSlides(slideIndex += 1); } let i; if (n > slides.length) { slideIndex = 1; } if (n < 1) { slideIndex = slides.length; } for (i = 0; i < slides.length; i++) { slides[i].style.display = "none"; } for (i = 0; i < dots.length; i++) { dots[i].className = dots[i].className.replace(" active", ""); } slides.eq(slideIndex - 2).find("img").addClass('lazypreload'); slides.eq(slideIndex - 1).css("display", "block"); dots.eq(slideIndex - 1).addClass("active"); } } let timer = setInterval(showSlides, 3500); $('.slideshow-container').hover(function () { clearInterval(timer); }, function () { timer = setInterval(showSlides, 3500); }); // ! Adding products $(document).on("click", '.add-to-cart', function (event) { event.preventDefault(); // Get product name to add $clickedBtn = $(this).attr('class').split(' ')[0]; $(this).parent().find(".operator").val($clickedBtn); $clickedForm = $(this).parent().attr('class').split(' ')[1]; $clickedFormTag = $(this); $(this).empty().append(""); // Start form submission $(this).parent().trigger("submit"); }); // ! Select related image base on variant $(document).on("change", '.variant_id, .variant_size', function (e) { if ($(this).hasClass("variant_size")) { $(this).closest("form").find(".variant_id").css("display", "none"); colorClass = "." + $(this).children(":selected").attr('class'); $(this).closest("form").find(".code-color").css("display", "flex"); $(this).closest("form").find(".select-color").css("display", "block"); $(this).closest("form").find(colorClass).css("display", "flex"); if (e.type == "change") { $("#variant-color").val(""); } $(this).closest("form").find(".code-color " + colorClass).trigger("click"); if ($(this).children(":selected").attr("price") !== undefined) { $(".product-price strong:eq(1)").text($(this).children(":selected").attr("price") + " "); } if ($(this).children(":selected").attr("old-price") !== undefined) { if ($(this).children(":selected").attr("old-price") !== "0") { $(".product-price del").text($(this).children(":selected").attr("old-price") + " ") } else { $(".product-price del").text("") } } } imageClass = "." + $(this).children(":selected").attr('class').split(' ').pop(); $(".slideshow-points " + imageClass).trigger("click"); sumItems(); }); $(document).on("click", '.variant_id', function () { $(this).closest("form").find(".variant_id").css("border", "0"); $(this).css("border", "4px solid rgb(57 57 57)"); imageClass = "." + $(this).attr('class').split(' ').pop(); $("#variant-color").val($(this).attr('variant')); $(".product-price strong:eq(1)").text($(this).attr("price") + " "); if ($(this).attr("old-price") !== "0") { $(".product-price del").text($(this).attr("old-price") + " ") } else { $(".product-price del").text("") } $(".slideshow-points " + imageClass).trigger("click"); sumItems(); }); if ($(".variant_size").length === 0) { $(".code-color div:eq(0)").trigger("click"); } if ($(".variant_size").val() !== null) { $(".variant_size").trigger("change"); } let $indexClicked = false; $(document).on("click", '.load-more', function (e) { e.preventDefault(); $(this).prop("disabled", true); if ($indexClicked === false) { $("#id_current_index").val($(".product--blue").length); $(".load-more button").append(""); $indexClicked = true; } $("#id_gender").trigger('change'); }); $(document).on("change", '.filter form select', function (e) { e.preventDefault(); $(".filter button").attr("disabled", true); if ($indexClicked === false) { $(".products-page .row").empty(); $("#id_current_index").val("0"); $(".products-page .row").append("