carhop__plugins__PROD-DEV/plugins/dynamiques-blocks/blocks/dernieres-dynamiques/build/dernieres-dynamiques/view.js
Antoine M 3c08c72aaf
All checks were successful
continuous-integration/drone/push Build is passing
REFACTOR for better syntax and responsive fix
2025-09-03 13:08:25 +02:00

65 lines
1.9 KiB
JavaScript

/******/ (() => { // webpackBootstrap
/*!******************************************!*\
!*** ./src/dernieres-dynamiques/view.js ***!
\******************************************/
function swiperCheckBreakpoints() {
const hasSwiper = dernieresDynamiquesSwiper.__swiper__ === true;
// if (window.innerWidth < 960 && hasSwiper) {
// dernieresDynamiquesSwiper.destroy(true, true);
// }
// if (window.innerWidth >= 960 && !hasSwiper) {
// initiateSwiper();
// }
}
function initiateSwiper() {
const currentBlock = document.querySelector(".block-dernieres-dynamiques");
if (!currentBlock) return;
const swiperFraction = currentBlock.querySelector(".swiper-pagination-fraction");
const slides = currentBlock.querySelectorAll(".swiper-slide");
const slideCount = slides.length;
swiperFraction.textContent = `Article n°1 sur ${slideCount}`;
dernieresDynamiquesSwiper = new Swiper(".dernieres-dynamiques-swiper", {
slidesPerView: 2,
spaceBetween: 30,
loop: true,
grabCursor: true,
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev"
},
pagination: {
el: ".swiper-pagination",
clickable: true,
renderBullet: function (index, className) {
return `<button class="${className}"></button>`;
}
},
breakpoints: {
// when window width is >= 320px
// when window width is >= 480px
320: {
slidesPerView: 1
},
// when window width is >= 640px
1100: {
slidesPerView: 2
}
},
on: {
slideChange: swiper => {
const slidesCount = swiper?.slides?.length;
swiperFraction.textContent = `Article n°${swiper.realIndex + 1} sur ${slidesCount}`;
}
}
});
}
window.addEventListener("DOMContentLoaded", event => {
initiateSwiper();
swiperCheckBreakpoints();
window.addEventListener("resize", swiperCheckBreakpoints);
});
/******/ })()
;
//# sourceMappingURL=view.js.map