| 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 initPostSlider = ($scope) => { |
| 10 |
const container = $scope[0]?.querySelector(".king-addons-post-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 autoplayPauseOnHover = settings.autoplayPauseOnHover === "yes"; |
| 25 |
const autoplayStopOnInteraction = settings.autoplayStopOnInteraction === "yes"; |
| 26 |
const loop = settings.loop === "yes"; |
| 27 |
const showPagination = settings.pagination === "yes"; |
| 28 |
const showNav = settings.navigation === "yes"; |
| 29 |
|
| 30 |
const config = { |
| 31 |
slidesPerView: slidesPerView, |
| 32 |
spaceBetween: spaceBetween, |
| 33 |
speed: speed, |
| 34 |
loop: loop, |
| 35 |
breakpoints: { |
| 36 |
0: { slidesPerView: slidesPerViewMobile }, |
| 37 |
768: { slidesPerView: slidesPerViewTablet }, |
| 38 |
1024: { slidesPerView: slidesPerView }, |
| 39 |
}, |
| 40 |
}; |
| 41 |
|
| 42 |
if (autoplay) { |
| 43 |
config.autoplay = { |
| 44 |
delay: autoplayDelay, |
| 45 |
disableOnInteraction: autoplayStopOnInteraction, |
| 46 |
pauseOnMouseEnter: autoplayPauseOnHover, |
| 47 |
}; |
| 48 |
} |
| 49 |
|
| 50 |
if (showPagination) { |
| 51 |
config.pagination = { |
| 52 |
el: container.querySelector(".king-addons-post-slider__pagination"), |
| 53 |
clickable: true, |
| 54 |
}; |
| 55 |
} |
| 56 |
|
| 57 |
if (showNav) { |
| 58 |
config.navigation = { |
| 59 |
nextEl: $scope[0].querySelector(".king-addons-post-slider__arrow--next"), |
| 60 |
prevEl: $scope[0].querySelector(".king-addons-post-slider__arrow--prev"), |
| 61 |
}; |
| 62 |
} |
| 63 |
|
| 64 |
// eslint-disable-next-line no-new |
| 65 |
const swiper = new Swiper(container, config); |
| 66 |
|
| 67 |
if (autoplay && autoplayStopOnInteraction) { |
| 68 |
const stopAutoplay = () => { |
| 69 |
if (!swiper.autoplay || !swiper.autoplay.running) { |
| 70 |
return; |
| 71 |
} |
| 72 |
|
| 73 |
swiper.autoplay.stop(); |
| 74 |
}; |
| 75 |
|
| 76 |
container.addEventListener("pointerdown", stopAutoplay, { passive: true }); |
| 77 |
container.addEventListener("touchstart", stopAutoplay, { passive: true }); |
| 78 |
container.addEventListener("mousedown", stopAutoplay); |
| 79 |
container.addEventListener("keydown", stopAutoplay); |
| 80 |
|
| 81 |
if (showNav) { |
| 82 |
const nextButton = $scope[0].querySelector(".king-addons-post-slider__arrow--next"); |
| 83 |
const prevButton = $scope[0].querySelector(".king-addons-post-slider__arrow--prev"); |
| 84 |
|
| 85 |
nextButton?.addEventListener("click", stopAutoplay); |
| 86 |
prevButton?.addEventListener("click", stopAutoplay); |
| 87 |
} |
| 88 |
|
| 89 |
if (showPagination) { |
| 90 |
const pagination = container.querySelector(".king-addons-post-slider__pagination"); |
| 91 |
pagination?.addEventListener("click", stopAutoplay); |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
// Card-level link handling: only bind on frontend to avoid blocking editor selection. |
| 96 |
const isEditMode = elementorFrontend.isEditMode(); |
| 97 |
if (!isEditMode) { |
| 98 |
const openCardLink = (slide) => { |
| 99 |
const url = slide.dataset.cardLink; |
| 100 |
if (!url) { |
| 101 |
return; |
| 102 |
} |
| 103 |
|
| 104 |
const target = slide.dataset.cardLinkTarget || "_self"; |
| 105 |
if (target === "_blank") { |
| 106 |
const newWindow = window.open(url, "_blank", "noopener"); |
| 107 |
if (newWindow) { |
| 108 |
newWindow.opener = null; |
| 109 |
} |
| 110 |
return; |
| 111 |
} |
| 112 |
|
| 113 |
window.location.href = url; |
| 114 |
}; |
| 115 |
|
| 116 |
container.addEventListener("click", (event) => { |
| 117 |
const slide = event.target.closest(".king-addons-post-slider__slide[data-card-link]"); |
| 118 |
if (!slide) { |
| 119 |
return; |
| 120 |
} |
| 121 |
|
| 122 |
if (event.target.closest("a")) { |
| 123 |
return; |
| 124 |
} |
| 125 |
|
| 126 |
openCardLink(slide); |
| 127 |
}); |
| 128 |
|
| 129 |
container.addEventListener("keydown", (event) => { |
| 130 |
if (event.key !== "Enter" && event.key !== " " && event.key !== "Spacebar" && event.key !== "Space") { |
| 131 |
return; |
| 132 |
} |
| 133 |
|
| 134 |
const slide = event.target.closest(".king-addons-post-slider__slide[data-card-link]"); |
| 135 |
if (!slide || event.target !== slide) { |
| 136 |
return; |
| 137 |
} |
| 138 |
|
| 139 |
event.preventDefault(); |
| 140 |
openCardLink(slide); |
| 141 |
}); |
| 142 |
} |
| 143 |
}; |
| 144 |
|
| 145 |
$(window).on("elementor/frontend/init", function () { |
| 146 |
elementorFrontend.hooks.addAction( |
| 147 |
"frontend/element_ready/king-addons-quick-post-slider.default", |
| 148 |
function ($scope) { |
| 149 |
initPostSlider($scope); |
| 150 |
} |
| 151 |
); |
| 152 |
}); |
| 153 |
})(jQuery); |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|