@@ -38,7 +38,6 @@ async function atomicCoveo() {
38
38
const searchBarHeader = document . querySelector ( '#search-standalone-header' ) ;
39
39
const searchBarSidebar = document . querySelector ( '#search-standalone-sidebar' ) ;
40
40
const sidebar = document . querySelector ( '#sidebar-layout' ) ;
41
- let searchbar ;
42
41
43
42
if ( searchPageInterface ) {
44
43
await searchPageInterface . initialize ( {
@@ -53,29 +52,42 @@ async function atomicCoveo() {
53
52
return request ;
54
53
} ,
55
54
} ) ;
56
- searchPageInterface . executeFirstSearch ( ) ;
55
+ await searchPageInterface . executeFirstSearch ( ) ;
57
56
} else {
58
- // If there is a searchbar, only initialize the searchbar for the sidebar.
59
57
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 ( ) ;
63
71
}
72
+ }
64
73
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 ) ;
73
83
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 ( ) ;
79
91
}
80
92
81
93
async function legacyCoveo ( ) {
@@ -146,3 +158,26 @@ document.addEventListener('DOMContentLoaded', async () => {
146
158
legacyCoveo ( ) ;
147
159
}
148
160
} ) ;
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