diff --git a/html/javascript/package-search.js b/html/javascript/package-search.js index e603853eda..c690632938 100644 --- a/html/javascript/package-search.js +++ b/html/javascript/package-search.js @@ -21,27 +21,38 @@ window.addEventListener("load", function (event) { search.setAttribute("placeholder", "Search packages..."); search.setAttribute("type", "search"); search.addEventListener("input", function(event) { - const query = new RegExp(event.target.value, "i"); + let query = event.target.value; + + if (!query) { // empty input + for (let i = 1; i < table.rows.length; i++) { + const row = table.rows.item(i); + const name = row.childNodes.item(0); + const desc = row.childNodes.item(2); + name.classList.remove("alt"); + desc.classList.remove("alt"); + row.classList.remove("invisible"); + } + return; + } + query = query.toLowerCase(); for (let i = 1; i < table.rows.length; i++) { const row = table.rows.item(i); - row.classList.remove("invisible"); const name = row.childNodes.item(0); - const name_matches = name.innerText.match(query); + const name_matches = name.innerText.toLowerCase().includes(query); name.classList.remove("alt"); const desc = row.childNodes.item(2); - const desc_matches = desc.innerText.match(query); + const desc_matches = desc.innerText.toLowerCase().includes(query); desc.classList.remove("alt"); - if (query) { // avoid matching the empty string - if (name_matches || desc_matches) { - if (name_matches) { name.classList.add("alt"); } - if (desc_matches) { desc.classList.add("alt"); } - } else { - row.classList.add("invisible"); - } + if (name_matches || desc_matches) { + row.classList.remove("invisible"); + if (name_matches) { name.classList.add("alt"); } + if (desc_matches) { desc.classList.add("alt"); } + } else { + row.classList.add("invisible"); } } });