mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-22 05:58:21 -05:00
Update pagination.js
This commit is contained in:
parent
73c7954283
commit
611cad7223
@ -1,26 +1,39 @@
|
|||||||
|
/**
|
||||||
|
* Navigates to the next page by incrementing the current page number in the URL query parameters.
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
function navigate_forward() {
|
function navigate_forward() {
|
||||||
const url = new URL(window.location)
|
const url = new URL(window.location);
|
||||||
const searchParams = url.searchParams
|
const searchParams = url.searchParams;
|
||||||
|
|
||||||
let q = searchParams.get('q')
|
let q = searchParams.get('q');
|
||||||
let page = searchParams.get('page')
|
let page = parseInt(searchParams.get('page'));
|
||||||
|
|
||||||
if (page === null) {
|
if (isNaN(page)) {
|
||||||
page = 2
|
page = 1;
|
||||||
window.location = `${url.origin}${url.pathname}?q=${q}&page=${page}`
|
|
||||||
} else {
|
} else {
|
||||||
window.location = `${url.origin}${url.pathname}?q=${q}&page=${++page}`
|
page++;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.location.href = `${url.origin}${url.pathname}?q=${encodeURIComponent(q)}&page=${page}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Navigates to the previous page by decrementing the current page number in the URL query parameters.
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
function navigate_backward() {
|
function navigate_backward() {
|
||||||
const url = new URL(window.location)
|
const url = new URL(window.location);
|
||||||
const searchParams = url.searchParams
|
const searchParams = url.searchParams;
|
||||||
|
|
||||||
let q = searchParams.get('q')
|
let q = searchParams.get('q');
|
||||||
let page = searchParams.get('page')
|
let page = parseInt(searchParams.get('page'));
|
||||||
|
|
||||||
if (page !== null && page > 1) {
|
if (isNaN(page)) {
|
||||||
window.location = `${url.origin}${url.pathname}?q=${q}&page=${--page}`
|
page = 1;
|
||||||
|
} else if (page > 1) {
|
||||||
|
page--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.location.href = `${url.origin}${url.pathname}?q=${encodeURIComponent(q)}&page=${page}`;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user