diff --git a/static/searchbox.js b/static/searchbox.js index a526d7d..ac16113 100644 --- a/static/searchbox.js +++ b/static/searchbox.js @@ -1,6 +1,36 @@ $(document).ready(function () { - PkgSite.staticJSON("search-completions", function (searchCompletions) { - searchCompletions.sort(); - PkgSite.multiTermComplete(PkgSite.preventTabMovingDuringSelection($("#q")), searchCompletions); - }); + // Get the search input element + const searchInput = $("#q"); + + // Function to filter packages based on search input + function filterPackages() { + const searchText = searchInput.val().toLowerCase(); + + // Filter each row in the package table + $("table.packages > tbody > tr").each(function() { + const row = $(this); + const packageName = row.find("td:nth-child(2) h2 a").text().toLowerCase(); + const authors = row.find("td:nth-child(2) .authors").text().toLowerCase(); + const description = row.find("td:nth-child(3) p:first-child").text().toLowerCase(); + const tags = row.find(".taglinks").text().toLowerCase(); + + // Show row if the search text is found in the package name, author, description or tags + if (searchText === "" || + packageName.includes(searchText) || + authors.includes(searchText) || + description.includes(searchText) || + tags.includes(searchText)) { + row.show(); + } else { + row.hide(); + } + }); + + // Update the package count + const visibleRows = $("table.packages > tbody > tr:visible").length; + $(".package-count:first").text(visibleRows + " packages" + (searchText ? " found" : "")); + } + + // Add input event listener to search box for real-time filtering + searchInput.on('input', filterPackages); }); diff --git a/static/site.js b/static/site.js index 3bf8a89..b1ecce2 100644 --- a/static/site.js +++ b/static/site.js @@ -45,15 +45,14 @@ PkgSite = (function () { $(document).ready(function () { $("table.sortable").tablesorter(); - if ($("#tags").length) { - PkgSite.dynamicJSON((document.body.className === "package-form") - ? "formal-tags" - : "tag-search-completions", - function (completions) { - completions.sort(); - PkgSite.multiTermComplete( - PkgSite.preventTabMovingDuringSelection($("#tags")), - completions); - }); + // Only apply autocomplete to the tags field in package edit form, not search fields + if ($("#tags").length && document.body.className === "package-form") { + PkgSite.dynamicJSON("formal-tags", + function (completions) { + completions.sort(); + PkgSite.multiTermComplete( + PkgSite.preventTabMovingDuringSelection($("#tags")), + completions); + }); } });