"use strict"; (function ($) { $("document").ready(function () { if (window.Swiper == null) { return; } const defaultConfig = { direction: "horizontal", slidesPerView: 1, spaceBetween: 10, breakpoints: { 1000: { slidesPerView: 2, }, }, }; const swiperConfig = window.brandyData?.blocks_data["woocommerce/product-image-gallery"] ?.swiper; setTimeout(() => { $(".brandy-product-image-gallery .woocommerce-product-gallery").each( (_, swiperEl) => { $(swiperEl).addClass("swiper"); const config = { grabCursor: true, ...defaultConfig, ...(swiperConfig?.data ?? {}), }; if ( $(swiperEl).find( ".woocommerce-product-gallery__wrapper .swiper-slide" ).length < 2 ) { Object.keys(config.breakpoints ?? {}).forEach((breakpoint) => { config.breakpoints[breakpoint].slidesPerView = 1; }); } const swiper = new Swiper(swiperEl, config); $(swiperEl) .closest(".brandy-product-image-gallery") .find(".brandy-swiper-navigation-button--back") .on("click", function () { swiper.slidePrev(); }); $(swiperEl) .closest(".brandy-product-image-gallery") .find(".brandy-swiper-navigation-button--next") .on("click", function () { swiper.slideNext(); }); function handleButtonStatus() { const backButtons = $(swiperEl) .closest(".brandy-product-image-gallery") .find(".brandy-swiper-navigation-button--back"); const nextButtons = $(swiperEl) .closest(".brandy-product-image-gallery") .find(".brandy-swiper-navigation-button--next"); const isBackDisabled = swiper.isBeginning; const isNextDisabled = swiper.isEnd; if (isBackDisabled) { backButtons.addClass("navigation-button--disabled"); } else { backButtons.removeClass("navigation-button--disabled"); } if (isNextDisabled) { nextButtons.addClass("navigation-button--disabled"); } else { nextButtons.removeClass("navigation-button--disabled"); } } swiper.on("slideChange", handleButtonStatus); swiper.on("resize", handleButtonStatus); } ); }, 0); }); })(window.jQuery);