Spaces:
Runtime error
Runtime error
Merge pull request #11 from alamin655/alamin655-patch-1
Browse files- public/static/index.js +21 -6
public/static/index.js
CHANGED
@@ -1,10 +1,25 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
}
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
7 |
if (e.key === 'Enter') {
|
8 |
-
|
9 |
}
|
10 |
-
})
|
|
|
1 |
+
/**
|
2 |
+
* Selects the input element for the search box
|
3 |
+
* @type {HTMLInputElement}
|
4 |
+
*/
|
5 |
+
const searchBox = document.querySelector('input');
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Redirects the user to the search results page with the query parameter
|
9 |
+
*/
|
10 |
+
function searchWeb() {
|
11 |
+
const query = searchBox.value.trim();
|
12 |
+
if (query) {
|
13 |
+
window.location.href = `search?q=${encodeURIComponent(query)}`;
|
14 |
+
}
|
15 |
}
|
16 |
|
17 |
+
/**
|
18 |
+
* Listens for the 'Enter' key press event on the search box and calls the searchWeb function
|
19 |
+
* @param {KeyboardEvent} e - The keyboard event object
|
20 |
+
*/
|
21 |
+
searchBox.addEventListener('keyup', (e) => {
|
22 |
if (e.key === 'Enter') {
|
23 |
+
searchWeb();
|
24 |
}
|
25 |
+
});
|