You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
1.1 KiB
29 lines
1.1 KiB
//#region js/pagination.js
|
|
function getCurrentPage() {
|
|
const activePage = Number($("[data-pagination] .d-pagination__page.is-active").attr("data-page") || 1);
|
|
return Number.isFinite(activePage) && activePage > 0 ? activePage : 1;
|
|
}
|
|
function goToPage(page) {
|
|
const nextPage = Number(page);
|
|
if (!Number.isFinite(nextPage) || nextPage < 1) return;
|
|
const url = new URL(window.location.href);
|
|
if (nextPage <= 1) url.searchParams.delete("page");
|
|
else url.searchParams.set("page", String(nextPage));
|
|
const query = url.searchParams.toString();
|
|
window.location.href = query ? `${url.pathname}?${query}` : url.pathname;
|
|
}
|
|
$(function() {
|
|
$(document).on("click", "[data-pagination] .d-pagination__page[data-page]", function() {
|
|
if ($(this).hasClass("is-active") || $(this).prop("disabled")) return;
|
|
goToPage($(this).attr("data-page"));
|
|
});
|
|
$(document).on("click", "[data-pagination] [data-page-prev]", function() {
|
|
if ($(this).prop("disabled")) return;
|
|
goToPage(getCurrentPage() - 1);
|
|
});
|
|
$(document).on("click", "[data-pagination] [data-page-next]", function() {
|
|
if ($(this).prop("disabled")) return;
|
|
goToPage(getCurrentPage() + 1);
|
|
});
|
|
});
|
|
//#endregion
|