@@ -21,10 +21,8 @@ async function getsearchObj() {
21
21
}
22
22
23
23
async function atomicCoveo ( ) {
24
+ /* Fetch the credentials */
24
25
await customElements . whenDefined ( 'atomic-search-interface' ) ;
25
- const searchInterface = document . querySelector ( '#search-v2' ) ;
26
- const searchInterfaceStandalone =
27
- document . querySelector ( '#search-standalone' ) ;
28
26
const token = localStorage . getItem ( 'coveo_jwt_v1' ) ;
29
27
const org_id = localStorage . getItem ( 'coveo_org_id_v1' ) ;
30
28
let searchObj = { token, org_id } ;
@@ -35,8 +33,15 @@ async function atomicCoveo() {
35
33
localStorage . setItem ( 'coveo_org_id_v1' , searchObj . org_id ) ;
36
34
}
37
35
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 ( {
40
45
accessToken : token ,
41
46
organizationId : org_id ,
42
47
analytics : { analyticsMode : 'legacy' } ,
@@ -48,22 +53,29 @@ async function atomicCoveo() {
48
53
return request ;
49
54
} ,
50
55
} ) ;
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
+ }
53
64
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 ) ;
62
73
63
- return request ;
64
- } ,
65
- } ) ;
66
- searchInterfaceStandalone . executeFirstSearch ( ) ;
74
+ return request ;
75
+ } ,
76
+ } ) ;
77
+ searchbar . executeFirstSearch ( ) ;
78
+ }
67
79
}
68
80
69
81
async function legacyCoveo ( ) {
0 commit comments