Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions static/searchbox.js
Original file line number Diff line number Diff line change
@@ -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);
});
19 changes: 9 additions & 10 deletions static/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
});