| 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 initCardSlider = ($scope) => { |
| 10 |
const container = $scope[0]?.querySelector(".king-addons-card-slider__track"); |
| 11 |
|
| 12 |
if (!container || typeof Swiper === "undefined") { |
| 13 |
return; |
| 14 |
} |
| 15 |
|
| 16 |
const settings = container.dataset; |
| 17 |
const slidesPerView = parseNumber(settings.slidesPerView, 1); |
| 18 |
const slidesPerViewTablet = parseNumber(settings.slidesPerViewTablet, slidesPerView); |
| 19 |
const slidesPerViewMobile = parseNumber(settings.slidesPerViewMobile, slidesPerViewTablet); |
| 20 |
const spaceBetween = parseNumber(settings.spaceBetween, 20); |
| 21 |
const speed = parseNumber(settings.speed, 600); |
| 22 |
const autoplay = settings.autoplay === "yes"; |
| 23 |
const autoplayDelay = parseNumber(settings.autoplayDelay, 3200); |
| 24 |
const loop = settings.loop === "yes"; |
| 25 |
const showPagination = settings.pagination === "yes"; |
| 26 |
const showNav = settings.navigation === "yes"; |
| 27 |
|
| 28 |
const config = { |
| 29 |
slidesPerView: slidesPerView, |
| 30 |
spaceBetween: spaceBetween, |
| 31 |
speed: speed, |
| 32 |
loop: loop, |
| 33 |
breakpoints: { |
| 34 |
0: { slidesPerView: slidesPerViewMobile }, |
| 35 |
768: { slidesPerView: slidesPerViewTablet }, |
| 36 |
1024: { slidesPerView: slidesPerView }, |
| 37 |
}, |
| 38 |
}; |
| 39 |
|
| 40 |
if (autoplay) { |
| 41 |
config.autoplay = { |
| 42 |
delay: autoplayDelay, |
| 43 |
disableOnInteraction: false, |
| 44 |
pauseOnMouseEnter: true, |
| 45 |
}; |
| 46 |
} |
| 47 |
|
| 48 |
if (showPagination) { |
| 49 |
config.pagination = { |
| 50 |
el: container.querySelector(".king-addons-card-slider__pagination"), |
| 51 |
clickable: true, |
| 52 |
}; |
| 53 |
} |
| 54 |
|
| 55 |
if (showNav) { |
| 56 |
config.navigation = { |
| 57 |
nextEl: $scope[0].querySelector(".king-addons-card-slider__arrow--next"), |
| 58 |
prevEl: $scope[0].querySelector(".king-addons-card-slider__arrow--prev"), |
| 59 |
}; |
| 60 |
} |
| 61 |
|
| 62 |
// eslint-disable-next-line no-new |
| 63 |
const swiper = new Swiper(container, config); |
| 64 |
|
| 65 |
// Card-level link handling: only bind on frontend to avoid blocking editor selection. |
| 66 |
const isEditMode = elementorFrontend.isEditMode(); |
| 67 |
if (!isEditMode) { |
| 68 |
const openCardLink = (slide) => { |
| 69 |
const url = slide.dataset.cardLink; |
| 70 |
if (!url) { |
| 71 |
return; |
| 72 |
} |
| 73 |
|
| 74 |
const target = slide.dataset.cardLinkTarget || "_self"; |
| 75 |
if (target === "_blank") { |
| 76 |
const newWindow = window.open(url, "_blank", "noopener"); |
| 77 |
if (newWindow) { |
| 78 |
newWindow.opener = null; |
| 79 |
} |
| 80 |
return; |
| 81 |
} |
| 82 |
|
| 83 |
window.location.href = url; |
| 84 |
}; |
| 85 |
|
| 86 |
container.addEventListener("click", (event) => { |
| 87 |
const slide = event.target.closest(".king-addons-card-slider__slide[data-card-link]"); |
| 88 |
if (!slide) { |
| 89 |
return; |
| 90 |
} |
| 91 |
|
| 92 |
if (event.target.closest("a")) { |
| 93 |
return; |
| 94 |
} |
| 95 |
|
| 96 |
openCardLink(slide); |
| 97 |
}); |
| 98 |
|
| 99 |
container.addEventListener("keydown", (event) => { |
| 100 |
if (event.key !== "Enter" && event.key !== " " && event.key !== "Spacebar" && event.key !== "Space") { |
| 101 |
return; |
| 102 |
} |
| 103 |
|
| 104 |
const slide = event.target.closest(".king-addons-card-slider__slide[data-card-link]"); |
| 105 |
if (!slide || event.target !== slide) { |
| 106 |
return; |
| 107 |
} |
| 108 |
|
| 109 |
event.preventDefault(); |
| 110 |
openCardLink(slide); |
| 111 |
}); |
| 112 |
} |
| 113 |
}; |
| 114 |
|
| 115 |
$(window).on("elementor/frontend/init", function () { |
| 116 |
elementorFrontend.hooks.addAction( |
| 117 |
"frontend/element_ready/king-addons-quick-card-slider.default", |
| 118 |
function ($scope) { |
| 119 |
initCardSlider($scope); |
| 120 |
} |
| 121 |
); |
| 122 |
}); |
| 123 |
})(jQuery); |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|