alamin655 commited on
Commit
73c7954
2 Parent(s): fad1fd3 5689d37

Merge pull request #11 from alamin655/alamin655-patch-1

Browse files
Files changed (1) hide show
  1. public/static/index.js +21 -6
public/static/index.js CHANGED
@@ -1,10 +1,25 @@
1
- let search_box = document.querySelector('input')
2
- function search_web() {
3
- window.location = `search?q=${search_box.value}`
 
 
 
 
 
 
 
 
 
 
 
4
  }
5
 
6
- search_box.addEventListener('keyup', (e) => {
 
 
 
 
7
  if (e.key === 'Enter') {
8
- search_web()
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
+ });