style: format static/continue_watching_carousel.ts
This commit is contained in:
@@ -27,8 +27,9 @@ const getContinueWatchingCarousel = (root: HTMLElement): ContinueWatchingCarouse
|
|||||||
return { track, previous, next, previousFade, nextFade };
|
return { track, previous, next, previousFade, nextFade };
|
||||||
};
|
};
|
||||||
|
|
||||||
const continueWatchingCarousels = (root: ParentNode = document): HTMLElement[] =>
|
const continueWatchingCarousels = (root: ParentNode = document): HTMLElement[] => [
|
||||||
Array.from(root.querySelectorAll<HTMLElement>("[data-continue-watching-carousel]"));
|
...root.querySelectorAll<HTMLElement>("[data-continue-watching-carousel]"),
|
||||||
|
];
|
||||||
|
|
||||||
const maxScrollLeft = (track: HTMLElement): number =>
|
const maxScrollLeft = (track: HTMLElement): number =>
|
||||||
Math.max(0, track.scrollWidth - track.clientWidth);
|
Math.max(0, track.scrollWidth - track.clientWidth);
|
||||||
@@ -89,18 +90,17 @@ const scrollContinueWatchingCarousel = (root: HTMLElement, direction: -1 | 1): v
|
|||||||
currentScroll + carouselScrollAmount(carousel.track),
|
currentScroll + carouselScrollAmount(carousel.track),
|
||||||
);
|
);
|
||||||
|
|
||||||
carousel.track.scrollTo({
|
carousel.track.scrollTo({ left: targetScroll, behavior: "smooth" });
|
||||||
left: targetScroll,
|
|
||||||
behavior: "smooth",
|
|
||||||
});
|
|
||||||
|
|
||||||
window.setTimeout(() => updateContinueWatchingCarousel(root), 350);
|
window.setTimeout(() => {
|
||||||
|
updateContinueWatchingCarousel(root);
|
||||||
|
}, 350);
|
||||||
};
|
};
|
||||||
|
|
||||||
document.addEventListener(
|
document.addEventListener(
|
||||||
"click",
|
"click",
|
||||||
(event: MouseEvent): void => {
|
(event: MouseEvent): void => {
|
||||||
const target = event.target;
|
const { target } = event;
|
||||||
if (!(target instanceof Element)) {
|
if (!(target instanceof Element)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -134,7 +134,7 @@ document.addEventListener(
|
|||||||
document.addEventListener(
|
document.addEventListener(
|
||||||
"scroll",
|
"scroll",
|
||||||
(event: Event): void => {
|
(event: Event): void => {
|
||||||
const target = event.target;
|
const { target } = event;
|
||||||
if (!(target instanceof HTMLElement) || !target.matches("[data-continue-watching-track]")) {
|
if (!(target instanceof HTMLElement) || !target.matches("[data-continue-watching-track]")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -147,6 +147,12 @@ document.addEventListener(
|
|||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
onReady(() => updateContinueWatchingCarousels());
|
onReady(() => {
|
||||||
onHtmxLoad((root) => updateContinueWatchingCarousels(root));
|
updateContinueWatchingCarousels();
|
||||||
window.addEventListener("resize", () => updateContinueWatchingCarousels());
|
});
|
||||||
|
onHtmxLoad((root) => {
|
||||||
|
updateContinueWatchingCarousels(root);
|
||||||
|
});
|
||||||
|
window.addEventListener("resize", () => {
|
||||||
|
updateContinueWatchingCarousels();
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user