11const SEARCH_BAR = document . getElementById ( "search-bar" ) ;
22const 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" ) ;
44const MAIN_PAGE_CONTENT = document . querySelector ( ".bd-main" ) ;
55let 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