alamin655
commited on
Commit
•
611cad7
1
Parent(s):
73c7954
Update pagination.js
Browse files- public/static/pagination.js +27 -14
public/static/pagination.js
CHANGED
@@ -1,26 +1,39 @@
|
|
|
|
|
|
|
|
|
|
1 |
function navigate_forward() {
|
2 |
-
const url = new URL(window.location)
|
3 |
-
const searchParams = url.searchParams
|
4 |
|
5 |
-
let q = searchParams.get('q')
|
6 |
-
let page = searchParams.get('page')
|
7 |
|
8 |
-
if (page
|
9 |
-
page =
|
10 |
-
window.location = `${url.origin}${url.pathname}?q=${q}&page=${page}`
|
11 |
} else {
|
12 |
-
|
13 |
}
|
|
|
|
|
14 |
}
|
15 |
|
|
|
|
|
|
|
|
|
16 |
function navigate_backward() {
|
17 |
-
const url = new URL(window.location)
|
18 |
-
const searchParams = url.searchParams
|
19 |
|
20 |
-
let q = searchParams.get('q')
|
21 |
-
let page = searchParams.get('page')
|
22 |
|
23 |
-
if (page
|
24 |
-
|
|
|
|
|
25 |
}
|
|
|
|
|
26 |
}
|
|
|
1 |
+
/**
|
2 |
+
* Navigates to the next page by incrementing the current page number in the URL query parameters.
|
3 |
+
* @returns {void}
|
4 |
+
*/
|
5 |
function navigate_forward() {
|
6 |
+
const url = new URL(window.location);
|
7 |
+
const searchParams = url.searchParams;
|
8 |
|
9 |
+
let q = searchParams.get('q');
|
10 |
+
let page = parseInt(searchParams.get('page'));
|
11 |
|
12 |
+
if (isNaN(page)) {
|
13 |
+
page = 1;
|
|
|
14 |
} else {
|
15 |
+
page++;
|
16 |
}
|
17 |
+
|
18 |
+
window.location.href = `${url.origin}${url.pathname}?q=${encodeURIComponent(q)}&page=${page}`;
|
19 |
}
|
20 |
|
21 |
+
/**
|
22 |
+
* Navigates to the previous page by decrementing the current page number in the URL query parameters.
|
23 |
+
* @returns {void}
|
24 |
+
*/
|
25 |
function navigate_backward() {
|
26 |
+
const url = new URL(window.location);
|
27 |
+
const searchParams = url.searchParams;
|
28 |
|
29 |
+
let q = searchParams.get('q');
|
30 |
+
let page = parseInt(searchParams.get('page'));
|
31 |
|
32 |
+
if (isNaN(page)) {
|
33 |
+
page = 1;
|
34 |
+
} else if (page > 1) {
|
35 |
+
page--;
|
36 |
}
|
37 |
+
|
38 |
+
window.location.href = `${url.origin}${url.pathname}?q=${encodeURIComponent(q)}&page=${page}`;
|
39 |
}
|