| 1 |
"use strict"; |
| 2 |
|
| 3 |
(function ($) { |
| 4 |
const parseNumber = (value, fallback) => { |
| 5 |
const number = parseInt(value, 10); |
| 6 |
return Number.isFinite(number) ? number : fallback; |
| 7 |
}; |
| 8 |
|
| 9 |
const initQuickProductSlider = ($scope) => { |
| 10 |
const container = $scope[0]?.querySelector(".king-addons-quick-product-slider__track"); |
| 11 |
if (!container || typeof Swiper === "undefined") { |
| 12 |
return; |
| 13 |
} |
| 14 |
|
| 15 |
const dataset = container.dataset; |
| 16 |
const slidesPerView = parseNumber(dataset.slidesPerView, 1); |
| 17 |
const slidesPerViewTablet = parseNumber(dataset.slidesPerViewTablet, slidesPerView); |
| 18 |
const slidesPerViewMobile = parseNumber(dataset.slidesPerViewMobile, slidesPerViewTablet); |
| 19 |
const spaceBetween = parseNumber(dataset.spaceBetween, 20); |
| 20 |
const slidesPerGroup = parseNumber(dataset.slidesPerGroup, 1); |
| 21 |
const speed = parseNumber(dataset.speed, 600); |
| 22 |
const autoplay = dataset.autoplay === "yes"; |
| 23 |
const autoplayDelay = parseNumber(dataset.autoplayDelay, 3200); |
| 24 |
const autoplayPauseOnHover = dataset.autoplayPauseOnHover === "yes"; |
| 25 |
const autoplayStopOnInteraction = dataset.autoplayStopOnInteraction === "yes"; |
| 26 |
const loop = dataset.loop === "yes"; |
| 27 |
const showNav = dataset.navigation === "yes"; |
| 28 |
const showPagination = dataset.pagination === "yes"; |
| 29 |
|
| 30 |
const config = { |
| 31 |
slidesPerView: slidesPerView, |
| 32 |
spaceBetween: spaceBetween, |
| 33 |
slidesPerGroup: slidesPerGroup, |
| 34 |
speed: speed, |
| 35 |
loop: loop, |
| 36 |
breakpoints: { |
| 37 |
0: { slidesPerView: slidesPerViewMobile }, |
| 38 |
768: { slidesPerView: slidesPerViewTablet }, |
| 39 |
1024: { slidesPerView: slidesPerView }, |
| 40 |
}, |
| 41 |
}; |
| 42 |
|
| 43 |
if (autoplay) { |
| 44 |
config.autoplay = { |
| 45 |
delay: autoplayDelay, |
| 46 |
disableOnInteraction: autoplayStopOnInteraction, |
| 47 |
pauseOnMouseEnter: autoplayPauseOnHover, |
| 48 |
}; |
| 49 |
} |
| 50 |
|
| 51 |
if (showPagination) { |
| 52 |
config.pagination = { |
| 53 |
el: container.querySelector(".king-addons-quick-product-slider__pagination"), |
| 54 |
clickable: true, |
| 55 |
}; |
| 56 |
} |
| 57 |
|
| 58 |
if (showNav) { |
| 59 |
config.navigation = { |
| 60 |
nextEl: $scope[0].querySelector(".king-addons-quick-product-slider__arrow--next"), |
| 61 |
prevEl: $scope[0].querySelector(".king-addons-quick-product-slider__arrow--prev"), |
| 62 |
}; |
| 63 |
} |
| 64 |
|
| 65 |
// eslint-disable-next-line no-new |
| 66 |
const swiper = new Swiper(container, config); |
| 67 |
|
| 68 |
if (autoplay && autoplayStopOnInteraction) { |
| 69 |
const stopAutoplay = () => { |
| 70 |
if (!swiper.autoplay || !swiper.autoplay.running) { |
| 71 |
return; |
| 72 |
} |
| 73 |
|
| 74 |
swiper.autoplay.stop(); |
| 75 |
}; |
| 76 |
|
| 77 |
container.addEventListener("pointerdown", stopAutoplay, { passive: true }); |
| 78 |
container.addEventListener("touchstart", stopAutoplay, { passive: true }); |
| 79 |
container.addEventListener("mousedown", stopAutoplay); |
| 80 |
container.addEventListener("keydown", stopAutoplay); |
| 81 |
|
| 82 |
if (showNav) { |
| 83 |
const nextButton = $scope[0].querySelector(".king-addons-quick-product-slider__arrow--next"); |
| 84 |
const prevButton = $scope[0].querySelector(".king-addons-quick-product-slider__arrow--prev"); |
| 85 |
|
| 86 |
nextButton?.addEventListener("click", stopAutoplay); |
| 87 |
prevButton?.addEventListener("click", stopAutoplay); |
| 88 |
} |
| 89 |
} |
| 90 |
}; |
| 91 |
|
| 92 |
$(window).on("elementor/frontend/init", function () { |
| 93 |
elementorFrontend.hooks.addAction( |
| 94 |
"frontend/element_ready/king-addons-quick-product-slider.default", |
| 95 |
function ($scope) { |
| 96 |
initQuickProductSlider($scope); |
| 97 |
} |
| 98 |
); |
| 99 |
}); |
| 100 |
})(jQuery); |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|