0
0
mirror of https://github.com/neon-mmd/websurfx.git synced 2024-11-25 07:28:22 -05:00
websurfx/public/static/index.js
alamin655 5689d372c3
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.
2023-06-07 16:14:54 +05:30

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();
}
});