Skip to content
Merged
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
1 change: 1 addition & 0 deletions doc/changelog.d/584.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: enable local page `Search` and default to PyData search on 'Enter'
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

<div class="search-bar pst-js-only" id="search-bar">
<form class="bd-search d-flex align-items-center" action="{{ pathto('search') }}" method="get">
<i class="fa-solid fa-magnifying-glass"></i>
<input type="search" class="form-control" name="q" placeholder="{{ theme_search_bar_text }}"
aria-label="{{ theme_search_bar_text }}" autocomplete="off" autocorrect="off"
autocapitalize="off" spellcheck="false"/>
<span class="search-button__kbd-shortcut">
<kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd>K</kbd>
</span>
</form>
<div id="search-results" class="search-results" style="display: none;" tabindex="0"></div>
<form class="bd-search d-flex align-items-center" action="{{ pathto('search') }}" method="get">
<i class="fa-solid fa-magnifying-glass"></i>
<input type="search" class="form-control" name="q" placeholder="{{ theme_search_bar_text }}"
aria-label="{{ theme_search_bar_text }}" autocomplete="off" autocorrect="off"
autocapitalize="off" spellcheck="false" />
<span class="search-button__kbd-shortcut">
<kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd>K</kbd>
</span>
</form>
<div id="static-search-results" class="static-search-results" style="display:none;" tabindex="0"></div>
</div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@import "ansys-sphinx-theme-variable.css";

.search-results {
.static-search-results {
display: flex;
flex-direction: column;
align-content: stretch;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const SEARCH_BAR = document.getElementById("search-bar");
const SEARCH_INPUT = SEARCH_BAR.querySelector(".bd-search input.form-control");
const RESULTS = document.getElementById("search-results");
const RESULTS = document.getElementById("static-search-results");
const MAIN_PAGE_CONTENT = document.querySelector(".bd-main");
let CURRENT_INDEX = -1;

Expand Down Expand Up @@ -28,12 +28,13 @@ require(["fuse"], function (Fuse) {
// Initialize Fuse when the data is fetched
function initializeFuse(data, options) {
fuse = new Fuse(data, options);
// add env variable "FUSE_ACTIVE" to indicate that the search is ready
document.documentElement.setAttribute("data-fuse_active", "true");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

// Expand the search bar input
function expandSearchInput() {
RESULTS.style.display = "flex";
searchingForResultsBanner();
SEARCH_INPUT.classList.add("expanded");
MAIN_PAGE_CONTENT.classList.add("blurred");
SEARCH_INPUT.focus();
Expand Down Expand Up @@ -115,7 +116,8 @@ require(["fuse"], function (Fuse) {
RESULTS.style.display = "flex";
const warningBanner = document.createElement("div");
warningBanner.className = "warning-banner";
warningBanner.textContent = "No results found.";
warningBanner.textContent =
"No results found. Press Enter for extended search.";
warningBanner.style.display = "block";
warningBanner.style.fontStyle = "italic";
RESULTS.appendChild(warningBanner);
Expand Down Expand Up @@ -187,6 +189,12 @@ require(["fuse"], function (Fuse) {
const href = resultItems[CURRENT_INDEX].dataset.href;
navigateToHref(href);
}
if (resultItems.length > 0) {
event.preventDefault(); // Prevent default enter action
const href = resultItems[0].dataset.href;
navigateToHref(href);
}

break;

case "ArrowDown":
Expand All @@ -205,7 +213,15 @@ require(["fuse"], function (Fuse) {
break;

default:
searchingForResultsBanner();
// if environment variable "FUSE_ACTIVE" is set to true
if (
document.documentElement.getAttribute("data-fuse_active") === "true"
) {
searchingForResultsBanner();
} else {
console.error("[AST]: Fuse is not active yet.");
RESULTS.style.display = "none";
}
handleSearchInput();
}
}
Expand Down
Loading