48 lines
1.7 KiB
TypeScript
48 lines
1.7 KiB
TypeScript
import { Carousel } from "bootstrap";
|
|
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
|
|
if (!document.querySelector("main.home-page")) {
|
|
return;
|
|
}
|
|
|
|
|
|
// * BR Carousel (With BS)
|
|
const lotsCarousel = document.getElementById("carousel-lots");
|
|
if (lotsCarousel) {
|
|
const playPauseBtn = document.getElementById("coupons-carousel-play-btn");
|
|
const carousel = Carousel.getOrCreateInstance(lotsCarousel, {
|
|
// * Start cycle on swipe (or play btn)
|
|
ride: true
|
|
});
|
|
let isRunning = false;
|
|
|
|
if (playPauseBtn) {
|
|
const updatePlayBtnStatus = () => {
|
|
// * Toggle once
|
|
if (!isRunning) {
|
|
playPauseBtn.children.item(0)?.classList.remove("d-none");
|
|
playPauseBtn.children.item(1)?.classList.add("d-none");
|
|
playPauseBtn.setAttribute('title', String(playPauseBtn.dataset['play']));
|
|
} else {
|
|
playPauseBtn.children.item(0)?.classList.add("d-none");
|
|
playPauseBtn.children.item(1)?.classList.remove("d-none");
|
|
playPauseBtn.setAttribute('title', String(playPauseBtn.dataset['stop']));
|
|
}
|
|
};
|
|
playPauseBtn.addEventListener("click", () => {
|
|
if (isRunning) {
|
|
carousel.pause(true);
|
|
} else {
|
|
carousel.cycle();
|
|
}
|
|
isRunning = !isRunning;
|
|
updatePlayBtnStatus();
|
|
});
|
|
lotsCarousel.addEventListener("slide.bs.carousel", () => {
|
|
isRunning = true;
|
|
updatePlayBtnStatus();
|
|
});
|
|
}
|
|
}
|
|
});
|