Skip to content

Commit

Permalink
Fix the auto-deselect-modal-filters bug
Browse files Browse the repository at this point in the history
  • Loading branch information
LilithHafner committed Feb 3, 2024
1 parent c44680f commit 75c77f6
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions assets/html/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ const worker_blob = new Blob([worker_str], { type: "text/javascript" });
const worker = new Worker(URL.createObjectURL(worker_blob));

/////// SEARCH MAIN ///////
const modal_filters = make_modal_body_filters(filters);

// Whether the worker is currently handling a search. This is a boolean
// as the worker only ever handles 1 or 0 searches at a time.
Expand All @@ -359,6 +358,9 @@ var last_search_text = "";
// in the DOM, is used compute the results to display on calls to update_search.
var unfiltered_results = [];

// Which filter is currently selected
var selected_filter = "";

$(document).on("input", ".documenter-search-input", function (event) {
if (!worker_is_running) {
launch_search();
Expand All @@ -383,13 +385,13 @@ worker.onmessage = function (e) {
};

$(document).on("click", ".search-filter", function () {
// Toggle classes (for UI & semantics)
if ($(this).hasClass("search-filter-selected")) {
$(this).removeClass("search-filter-selected");
selected_filter = "";
} else {
$(this).addClass("search-filter-selected");
selected_filter = $(this).text().toLowerCase();
}

// This updates search results and toggles classes for UI:
update_search();
});

Expand All @@ -412,6 +414,7 @@ function update_search() {
}

let search_result_container = ``;
let modal_filters = make_modal_body_filters();
let search_divider = `<div class="search-divider w-100"></div>`;

if (results.length) {
Expand Down Expand Up @@ -477,13 +480,16 @@ function update_search() {
/**
* Make the modal filter html
*
* @param {string[]} filters
* @returns string
*/
function make_modal_body_filters(filters) {
function make_modal_body_filters() {
let str = filters
.map((val) => {
return `<a href="javascript:;" class="search-filter"><span>${val}</span></a>`;
if (selected_filter == val.toLowerCase()) {
return `<a href="javascript:;" class="search-filter search-filter-selected"><span>${val}</span></a>`;
} else {
return `<a href="javascript:;" class="search-filter"><span>${val}</span></a>`;
}
})
.join("");

Expand Down

0 comments on commit 75c77f6

Please sign in to comment.