0
0
mirror of https://github.com/neon-mmd/websurfx.git synced 2024-11-22 14:08:23 -05:00
websurfx/public/static/pagination.js

40 lines
1.0 KiB
JavaScript
Raw Normal View History

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