mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-23 06:28:23 -05:00
5689d372c3
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.
26 lines
626 B
JavaScript
26 lines
626 B
JavaScript
/**
|
|
* Selects the input element for the search box
|
|
* @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)}`;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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') {
|
|
searchWeb();
|
|
}
|
|
});
|