@@ -38,7 +38,6 @@ async function atomicCoveo() {
3838 const searchBarHeader = document . querySelector ( '#search-standalone-header' ) ;
3939 const searchBarSidebar = document . querySelector ( '#search-standalone-sidebar' ) ;
4040 const sidebar = document . querySelector ( '#sidebar-layout' ) ;
41- let searchbar ;
4241
4342 if ( searchPageInterface ) {
4443 await searchPageInterface . initialize ( {
@@ -53,29 +52,42 @@ async function atomicCoveo() {
5352 return request ;
5453 } ,
5554 } ) ;
56- searchPageInterface . executeFirstSearch ( ) ;
55+ await searchPageInterface . executeFirstSearch ( ) ;
5756 } else {
58- // If there is a searchbar, only initialize the searchbar for the sidebar.
5957 if ( sidebar ) {
60- searchbar = searchBarSidebar ;
61- } else {
62- searchbar = searchBarHeader ;
58+ await searchBarSidebar . initialize ( {
59+ accessToken : token ,
60+ organizationId : org_id ,
61+ analytics : { analyticsMode : 'legacy' } ,
62+ preprocessRequest : ( request , clientOrigin , metadata ) => {
63+ const body = JSON . parse ( request . body ) ;
64+ body . q = `<@- ${ body . q } -@>` ;
65+ request . body = JSON . stringify ( body ) ;
66+
67+ return request ;
68+ } ,
69+ } ) ;
70+ await searchBarSidebar . executeFirstSearch ( ) ;
6371 }
72+ }
6473
65- await searchbar . initialize ( {
66- accessToken : token ,
67- organizationId : org_id ,
68- analytics : { analyticsMode : 'legacy' } ,
69- preprocessRequest : ( request , clientOrigin , metadata ) => {
70- const body = JSON . parse ( request . body ) ;
71- body . q = `<@- ${ body . q } -@>` ;
72- request . body = JSON . stringify ( body ) ;
74+ /* Initialize the header searchbar*/
75+ await searchBarHeader . initialize ( {
76+ accessToken : token ,
77+ organizationId : org_id ,
78+ analytics : { analyticsMode : 'legacy' } ,
79+ preprocessRequest : ( request , clientOrigin , metadata ) => {
80+ const body = JSON . parse ( request . body ) ;
81+ body . q = `<@- ${ body . q } -@>` ;
82+ request . body = JSON . stringify ( body ) ;
7383
74- return request ;
75- } ,
76- } ) ;
77- searchbar . executeFirstSearch ( ) ;
78- }
84+ return request ;
85+ } ,
86+ } ) ;
87+
88+ searchBarHeader . style . display =
89+ sidebar || searchPageInterface ? 'none' : 'block' ;
90+ await searchBarHeader . executeFirstSearch ( ) ;
7991}
8092
8193async function legacyCoveo ( ) {
@@ -146,3 +158,26 @@ document.addEventListener('DOMContentLoaded', async () => {
146158 legacyCoveo ( ) ;
147159 }
148160} ) ;
161+
162+ window . addEventListener ( 'resize' , ( event ) => {
163+ const searchBarHeader = document . querySelector ( '#search-standalone-header' ) ;
164+ const searchPageInterface = document . querySelector ( '#search-v2' ) ;
165+ const searchPageSearchbar = document . querySelector (
166+ '#search-standalone-searchpage'
167+ ) ;
168+ const sidebar = document . querySelector ( '#sidebar-layout' ) ;
169+
170+ if ( ! sidebar && ! searchPageInterface ) {
171+ // Show when there is no sidebar or on the search page
172+ searchBarHeader . style . display = 'block' ;
173+ } else if ( sidebar && sidebar . offsetWidth === 0 ) {
174+ // Show when there is a sidebar but is hidden due to resizing
175+ searchBarHeader . style . display = 'block' ;
176+ } else if ( searchPageInterface && searchPageSearchbar . offsetWidth === 0 ) {
177+ // Show when on the search page but is "sidebar" searchbar is hidden
178+ searchBarHeader . style . display = 'block' ;
179+ } else {
180+ // Go back to default state
181+ searchBarHeader . style . display = 'none' ;
182+ }
183+ } ) ;
0 commit comments