mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-22 05:58:21 -05:00
Update search functionality with improved code
This commit updates the search functionality on the website with improved code that is more readable and maintainable. The code has been refactored to use more descriptive variable and function names, and comments have been added to clarify the purpose of each block of code. Template literals and encodeURIComponent have been used to ensure proper formatting of the search query parameter, and a check has been added to ensure that the search query is not empty before redirecting the user. This update should improve the user experience by providing more reliable and consistent search functionality. The code has been tested locally to ensure that it works as intended, and no changes were made to the UI or design of the search box and results page.
This commit is contained in:
parent
fad1fd34d9
commit
5689d372c3
@ -1,10 +1,25 @@
|
|||||||
let search_box = document.querySelector('input')
|
/**
|
||||||
function search_web() {
|
* Selects the input element for the search box
|
||||||
window.location = `search?q=${search_box.value}`
|
* @type {HTMLInputElement}
|
||||||
|
*/
|
||||||
|
const searchBox = document.querySelector('input');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redirects the user to the search results page with the query parameter
|
||||||
|
*/
|
||||||
|
function searchWeb() {
|
||||||
|
const query = searchBox.value.trim();
|
||||||
|
if (query) {
|
||||||
|
window.location.href = `search?q=${encodeURIComponent(query)}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
search_box.addEventListener('keyup', (e) => {
|
/**
|
||||||
|
* Listens for the 'Enter' key press event on the search box and calls the searchWeb function
|
||||||
|
* @param {KeyboardEvent} e - The keyboard event object
|
||||||
|
*/
|
||||||
|
searchBox.addEventListener('keyup', (e) => {
|
||||||
if (e.key === 'Enter') {
|
if (e.key === 'Enter') {
|
||||||
search_web()
|
searchWeb();
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user