@@ -7,9 +7,14 @@ function handleBurgerClick(el) {
77
88// search
99
10- function showSearchModal ( ) {
10+ function isSearchModalActive ( ) {
1111 const modal = document . getElementById ( "search-modal" ) ;
12- if ( ! modal . classList . contains ( "bulma-is-active" ) ) {
12+ return modal . classList . contains ( "bulma-is-active" ) ;
13+ }
14+
15+ function showSearchModal ( ) {
16+ if ( ! isSearchModalActive ( ) ) {
17+ const modal = document . getElementById ( "search-modal" ) ;
1318 modal . classList . add ( "bulma-is-active" ) ;
1419 const input = document . getElementById ( "search-input" ) ;
1520 input . value = "" ;
@@ -20,9 +25,10 @@ function showSearchModal() {
2025}
2126
2227function hideSearchModal ( ) {
23- const modal = document . getElementById ( "search-modal" ) ;
24- if ( modal . classList . contains ( "bulma-is-active" ) )
28+ if ( isSearchModalActive ( ) ) {
29+ const modal = document . getElementById ( "search-modal" ) ;
2530 modal . classList . remove ( "bulma-is-active" ) ;
31+ }
2632}
2733
2834function renderHit ( hit ) {
@@ -62,11 +68,11 @@ function onSearchInput(event) {
6268// Keyboard shortcuts: `/` to open, `Escape` to close
6369window . addEventListener ( "keydown" , ( event ) => {
6470 if ( event . defaultPrevented ) return ;
65- if ( event . code == "Slash" ) {
71+ if ( event . code == "Slash" && ! isSearchModalActive ( ) ) {
6672 event . preventDefault ( ) ;
6773 showSearchModal ( ) ;
6874 }
69- if ( event . code == "Escape" ) {
75+ if ( event . code == "Escape" && isSearchModalActive ( ) ) {
7076 event . preventDefault ( ) ;
7177 hideSearchModal ( ) ;
7278 }
0 commit comments