crabbysearch/public/static/pagination.js

40 lines
1,018 B
JavaScript
Raw Normal View History

2023-06-07 22:07:35 +05:30
/**
* Navigates to the next page by incrementing the current page number in the URL query string.
2023-06-07 22:07:35 +05:30
* @returns {void}
*/
function navigate_forward() {
let url = new URL(window.location);
let searchParams = url.searchParams;
2023-06-07 22:07:35 +05:30
let q = searchParams.get('q');
let page = parseInt(searchParams.get('page'));
2023-06-07 22:07:35 +05:30
if (isNaN(page)) {
page = 1;
} else {
2023-06-07 22:07:35 +05:30
page++;
}
2023-06-07 22:07:35 +05:30
window.location.href = `${url.origin}${url.pathname}?q=${encodeURIComponent(q)}&page=${page}`;
}
2023-06-07 22:07:35 +05:30
/**
* Navigates to the previous page by decrementing the current page number in the URL query string.
2023-06-07 22:07:35 +05:30
* @returns {void}
*/
function navigate_backward() {
let url = new URL(window.location);
let searchParams = url.searchParams;
2023-06-07 22:07:35 +05:30
let q = searchParams.get('q');
let page = parseInt(searchParams.get('page'));
2023-06-07 22:07:35 +05:30
if (isNaN(page)) {
page = 0;
} else if (page > 0) {
2023-06-07 22:07:35 +05:30
page--;
}
2023-06-07 22:07:35 +05:30
window.location.href = `${url.origin}${url.pathname}?q=${encodeURIComponent(q)}&page=${page}`;
}