6 const [startList, scrollableList, endList] = $(target).children();
7 const [scrollableFirstItem] = $(scrollableList).children().first();
8 const [scrollableLastItem] = $(scrollableList).children().last();
10 if (scrollableFirstItem) {
11 this.scrollStartObserver = createScrollObserver(startList, "2px 0px");
12 this.scrollStartObserver.observe(scrollableFirstItem);
15 if (scrollableLastItem) {
16 this.scrollEndObserver = createScrollObserver(endList, "-2px 0px");
17 this.scrollEndObserver.observe(scrollableLastItem);
20 function createScrollObserver(shadowTarget, shadowOffset) {
21 const threshold = 0.95;
22 return new IntersectionObserver(([entry]) => {
23 const floating = entry.intersectionRatio < threshold;
25 .css("box-shadow", floating ? `rgba(0, 0, 0, 0.075) ${shadowOffset} 2px` : "")
26 .css("z-index", floating ? "5" : ""); // floating z-index should be larger than z-index of Bootstrap's .page-link:focus, which is 3
32 this.scrollStartObserver?.disconnect();
33 this.scrollEndObserver?.disconnect();
37 $(document).on("click", "a.numbered_pagination_link", function (e) {
38 const targetItemId = $(this).attr("href");
39 const $targetItem = $(targetItemId);
40 $targetItem.trigger("numbered_pagination:center");
41 $targetItem.find("a.page-link").trigger("focus");
45 $(document).on("numbered_pagination:enable", ".numbered_pagination", function () {
46 shadowEffect = new ShadowEffect(this);
47 $(this).trigger("numbered_pagination:center");
50 $(document).on("numbered_pagination:disable", ".numbered_pagination", function () {
51 shadowEffect?.disable();
55 $(document).on("numbered_pagination:center", ".numbered_pagination", function () {
56 const [startList, scrollableList] = $(this).children();
58 if (!scrollableList) return;
60 const [activeStartItem] = $(startList).find(".page-item.active");
61 const [activeScrollableItem] = $(scrollableList).find(".page-item.active");
63 if (activeStartItem) {
64 scrollableList.scrollLeft = 0;
65 } else if (activeScrollableItem) {
66 scrollableList.scrollLeft = Math.round(activeScrollableItem.offsetLeft - (scrollableList.offsetWidth / 2) + (activeScrollableItem.offsetWidth / 2));
68 scrollableList.scrollLeft = scrollableList.scrollWidth - scrollableList.offsetWidth;