@@ -83,37 +83,23 @@ function createComponent(html) {
8383 // Event listeners for search
8484 // --------------------------------------------------------------------------------------------------
8585
86+ // Toggle open search bar (small screens)
8687 searchIcon . addEventListener ( "click" , ( ) => {
8788 if ( window . innerWidth <= 1023 ) {
8889 if ( siteHeader . style . display === "block" ) {
89- siteHeader . style . display = "none" ;
90- searchInput . style . display = "block" ;
91- navigation . classList . add ( "search-bar-open" ) ;
92- searchForm . classList . add ( "search-bar-open" ) ;
93- searchBar . classList . add ( "search-bar-open" ) ;
90+ openSearchBar ( ) ;
9491 } else {
95- siteHeader . style . display = "block" ;
96- searchInput . style . display = "none" ;
97- navigation . classList . remove ( "search-bar-open" ) ;
98- searchForm . classList . remove ( "search-bar-open" ) ;
99- searchBar . classList . remove ( "search-bar-open" ) ;
92+ closeSearchBar ( "block" , "none" ) ;
10093 }
10194 }
10295 } ) ;
10396
97+ // Toggle open search bar (on screen resize)
10498 window . addEventListener ( "resize" , ( ) => {
10599 if ( window . innerWidth >= 1024 ) {
106- siteHeader . style . display = "block" ;
107- searchInput . style . display = "block" ;
108- navigation . classList . remove ( "search-bar-open" ) ;
109- searchForm . classList . remove ( "search-bar-open" ) ;
110- searchBar . classList . remove ( "search-bar-open" ) ;
100+ closeSearchBar ( "block" , "block" ) ;
111101 } else {
112- siteHeader . style . display = "block" ;
113- searchInput . style . display = "none" ;
114- navigation . classList . remove ( "search-bar-open" ) ;
115- searchForm . classList . remove ( "search-bar-open" ) ;
116- searchBar . classList . remove ( "search-bar-open" ) ;
102+ closeSearchBar ( "block" , "none" ) ;
117103 }
118104 } ) ;
119105
@@ -218,6 +204,23 @@ function createComponent(html) {
218204 arrow . classList . toggle ( "rotArrow" ) ;
219205 desc . classList . toggle ( "search_content_drop" ) ;
220206 }
207+
208+ // Open search bar
209+ function openSearchBar ( ) {
210+ siteHeader . style . display = "none" ;
211+ searchInput . style . display = "block" ;
212+ navigation . classList . add ( "search-bar-open" ) ;
213+ searchForm . classList . add ( "search-bar-open" ) ;
214+ searchBar . classList . add ( "search-bar-open" ) ;
215+ }
216+
217+ function closeSearchBar ( headerState , inputState ) {
218+ siteHeader . style . display = headerState ;
219+ searchInput . style . display = inputState ;
220+ navigation . classList . remove ( "search-bar-open" ) ;
221+ searchForm . classList . remove ( "search-bar-open" ) ;
222+ searchBar . classList . remove ( "search-bar-open" ) ;
223+ }
221224 }
222225 }
223226
0 commit comments