@@ -21,10 +21,8 @@ async function getsearchObj() {
2121}
2222
2323async function atomicCoveo ( ) {
24+ /* Fetch the credentials */
2425 await customElements . whenDefined ( 'atomic-search-interface' ) ;
25- const searchInterface = document . querySelector ( '#search-v2' ) ;
26- const searchInterfaceStandalone =
27- document . querySelector ( '#search-standalone' ) ;
2826 const token = localStorage . getItem ( 'coveo_jwt_v1' ) ;
2927 const org_id = localStorage . getItem ( 'coveo_org_id_v1' ) ;
3028 let searchObj = { token, org_id } ;
@@ -35,8 +33,15 @@ async function atomicCoveo() {
3533 localStorage . setItem ( 'coveo_org_id_v1' , searchObj . org_id ) ;
3634 }
3735
38- if ( searchInterface ) {
39- await searchInterface . initialize ( {
36+ /* Initialize the interfaces with credentials */
37+ const searchPageInterface = document . querySelector ( '#search-v2' ) ;
38+ const searchBarHeader = document . querySelector ( '#search-standalone-header' ) ;
39+ const searchBarSidebar = document . querySelector ( '#search-standalone-sidebar' ) ;
40+ const sidebar = document . querySelector ( '#sidebar-layout' ) ;
41+ let searchbar ;
42+
43+ if ( searchPageInterface ) {
44+ await searchPageInterface . initialize ( {
4045 accessToken : token ,
4146 organizationId : org_id ,
4247 analytics : { analyticsMode : 'legacy' } ,
@@ -48,22 +53,29 @@ async function atomicCoveo() {
4853 return request ;
4954 } ,
5055 } ) ;
51- searchInterface . executeFirstSearch ( ) ;
52- }
56+ searchPageInterface . executeFirstSearch ( ) ;
57+ } else {
58+ // If there is a searchbar, only initialize the searchbar for the sidebar.
59+ if ( sidebar ) {
60+ searchbar = searchBarSidebar ;
61+ } else {
62+ searchbar = searchBarHeader ;
63+ }
5364
54- await searchInterfaceStandalone . initialize ( {
55- accessToken : token ,
56- organizationId : org_id ,
57- analytics : { analyticsMode : 'legacy' } ,
58- preprocessRequest : ( request , clientOrigin , metadata ) => {
59- const body = JSON . parse ( request . body ) ;
60- body . q = `<@- ${ body . q } -@>` ;
61- request . body = JSON . stringify ( body ) ;
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 ) ;
6273
63- return request ;
64- } ,
65- } ) ;
66- searchInterfaceStandalone . executeFirstSearch ( ) ;
74+ return request ;
75+ } ,
76+ } ) ;
77+ searchbar . executeFirstSearch ( ) ;
78+ }
6779}
6880
6981async function legacyCoveo ( ) {
0 commit comments