Skip to content

Commit 1544c84

Browse files
Revathyvenugopal162pyansys-ci-botjorgepiloto
authored
fix: enable local page Search and default to PyData search on 'Enter' (#584)
Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Jorge Martínez <[email protected]>
1 parent 3206583 commit 1544c84

File tree

5 files changed

+32
-24
lines changed

5 files changed

+32
-24
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fix: enable local page `Search` and default to PyData search on 'Enter'
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

22
<div class="search-bar pst-js-only" id="search-bar">
3-
<form class="bd-search d-flex align-items-center" action="{{ pathto('search') }}" method="get">
4-
<i class="fa-solid fa-magnifying-glass"></i>
5-
<input type="search" class="form-control" name="q" placeholder="{{ theme_search_bar_text }}"
6-
aria-label="{{ theme_search_bar_text }}" autocomplete="off" autocorrect="off"
7-
autocapitalize="off" spellcheck="false"/>
8-
<span class="search-button__kbd-shortcut">
9-
<kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd>K</kbd>
10-
</span>
11-
</form>
12-
<div id="search-results" class="search-results" style="display: none;" tabindex="0"></div>
3+
<form class="bd-search d-flex align-items-center" action="{{ pathto('search') }}" method="get">
4+
<i class="fa-solid fa-magnifying-glass"></i>
5+
<input type="search" class="form-control" name="q" placeholder="{{ theme_search_bar_text }}"
6+
aria-label="{{ theme_search_bar_text }}" autocomplete="off" autocorrect="off"
7+
autocapitalize="off" spellcheck="false" />
8+
<span class="search-button__kbd-shortcut">
9+
<kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd>K</kbd>
10+
</span>
11+
</form>
12+
<div id="static-search-results" class="static-search-results" style="display:none;" tabindex="0"></div>
1313
</div>

src/ansys_sphinx_theme/theme/ansys_sphinx_theme/static/css/ast-search.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@import "ansys-sphinx-theme-variable.css";
22

3-
.search-results {
3+
.static-search-results {
44
display: flex;
55
flex-direction: column;
66
align-content: stretch;

src/ansys_sphinx_theme/theme/ansys_sphinx_theme/static/js/pydata_search.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/ansys_sphinx_theme/theme/ansys_sphinx_theme/static/js/search.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const SEARCH_BAR = document.getElementById("search-bar");
22
const SEARCH_INPUT = SEARCH_BAR.querySelector(".bd-search input.form-control");
3-
const RESULTS = document.getElementById("search-results");
3+
const RESULTS = document.getElementById("static-search-results");
44
const MAIN_PAGE_CONTENT = document.querySelector(".bd-main");
55
let CURRENT_INDEX = -1;
66

@@ -28,12 +28,13 @@ require(["fuse"], function (Fuse) {
2828
// Initialize Fuse when the data is fetched
2929
function initializeFuse(data, options) {
3030
fuse = new Fuse(data, options);
31+
// add env variable "FUSE_ACTIVE" to indicate that the search is ready
32+
document.documentElement.setAttribute("data-fuse_active", "true");
3133
}
3234

3335
// Expand the search bar input
3436
function expandSearchInput() {
3537
RESULTS.style.display = "flex";
36-
searchingForResultsBanner();
3738
SEARCH_INPUT.classList.add("expanded");
3839
MAIN_PAGE_CONTENT.classList.add("blurred");
3940
SEARCH_INPUT.focus();
@@ -115,7 +116,8 @@ require(["fuse"], function (Fuse) {
115116
RESULTS.style.display = "flex";
116117
const warningBanner = document.createElement("div");
117118
warningBanner.className = "warning-banner";
118-
warningBanner.textContent = "No results found.";
119+
warningBanner.textContent =
120+
"No results found. Press Enter for extended search.";
119121
warningBanner.style.display = "block";
120122
warningBanner.style.fontStyle = "italic";
121123
RESULTS.appendChild(warningBanner);
@@ -187,6 +189,12 @@ require(["fuse"], function (Fuse) {
187189
const href = resultItems[CURRENT_INDEX].dataset.href;
188190
navigateToHref(href);
189191
}
192+
if (resultItems.length > 0) {
193+
event.preventDefault(); // Prevent default enter action
194+
const href = resultItems[0].dataset.href;
195+
navigateToHref(href);
196+
}
197+
190198
break;
191199

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

207215
default:
208-
searchingForResultsBanner();
216+
// if environment variable "FUSE_ACTIVE" is set to true
217+
if (
218+
document.documentElement.getAttribute("data-fuse_active") === "true"
219+
) {
220+
searchingForResultsBanner();
221+
} else {
222+
console.error("[AST]: Fuse is not active yet.");
223+
RESULTS.style.display = "none";
224+
}
209225
handleSearchInput();
210226
}
211227
}

0 commit comments

Comments
 (0)