diff --git a/assets/css/v2/style.css b/assets/css/v2/style.css index aad51f1..0dabcc7 100644 --- a/assets/css/v2/style.css +++ b/assets/css/v2/style.css @@ -217,7 +217,6 @@ nav { .sidebar-layout { display: flex; flex-direction: column; - z-index: 9999; } @media (max-width: 1528px) { @@ -371,6 +370,81 @@ nav { display: flex; } +/* Coveo */ +#search-v2 { + display: inline-block !important; + width: 95vw; + grid-column: 1 / -1; +} + +atomic-search-box { + &::part(wrapper) { + border-radius: 0; + border-color: black; + } + + &::part(suggestions-wrapper) { + border-radius: 0; + border-color: black; + width: calc(100% + 2px); + margin-left: -1px; + } +} + +atomic-query-summary { + /* Show duration */ + &::part(duration) { + display: inline-block !important; + } +} + +atomic-search-layout { + grid-template-areas: + "atomic-section-search" + "atomic-section-main" + "." !important; + + grid-template-columns: minmax(50%, 100%) !important; + + @media (min-width: 1024px) { + grid-template-areas: + ". atomic-section-search" + "atomic-section-facets atomic-section-main " + "atomic-section-facets . " !important; + + grid-template-columns: minmax(17rem, 24rem) minmax(50%, 100%) !important; + column-gap: calc(1.5rem + 2rem) !important; + } +} + +atomic-search-layout atomic-layout-section[section="search"] { + /* Override Coveo's width to be full */ + max-width: 100%; + width: 100% !important; +} + +.atomic-full-summary-and-sort { + display: flex; + flex-direction: column; + align-items: start; + gap: 1rem; + justify-content: space-between; + + @media (min-width: 480px) { + flex-direction: row; + align-items: center; + } + + atomic-sort-dropdown::part(label) { + margin-left: 0; + } +} + +#atomic-search-box-xqtsq-popup { + z-index: 9999; +} + +/* Sidebar */ .sidebar { display: flex; flex-direction: column; diff --git a/assets/js/coveo.js b/assets/js/coveo.js index a3ef7d0..eb4be86 100644 --- a/assets/js/coveo.js +++ b/assets/js/coveo.js @@ -20,7 +20,51 @@ async function getsearchObj() { return response.json(); } -document.addEventListener('DOMContentLoaded', async () => { +async function atomicCoveo() { + await customElements.whenDefined('atomic-search-interface'); + const searchInterface = document.querySelector('#search-v2'); + const searchInterfaceStandalone = + document.querySelector('#search-standalone'); + const token = localStorage.getItem('coveo_jwt_v1'); + const org_id = localStorage.getItem('coveo_org_id_v1'); + let searchObj = { token, org_id }; + + if (token === null || org_id === null || isJwtExpired(token)) { + searchObj = await getsearchObj(); + localStorage.setItem('coveo_jwt_v1', searchObj.token); + localStorage.setItem('coveo_org_id_v1', searchObj.org_id); + } + + if (searchInterface) { + await searchInterface.initialize({ + accessToken: token, + organizationId: org_id, + preprocessRequest: (request, clientOrigin, metadata) => { + const body = JSON.parse(request.body); + body.q = `<@- ${body.q} -@>`; + request.body = JSON.stringify(body); + + return request; + }, + }); + searchInterface.executeFirstSearch(); + } + + await searchInterfaceStandalone.initialize({ + accessToken: token, + organizationId: org_id, + preprocessRequest: (request, clientOrigin, metadata) => { + const body = JSON.parse(request.body); + body.q = `<@- ${body.q} -@>`; + request.body = JSON.stringify(body); + + return request; + }, + }); + searchInterfaceStandalone.executeFirstSearch(); +} + +async function legacyCoveo() { const token = localStorage.getItem('coveo_jwt_v1'); const org_id = localStorage.getItem('coveo_org_id_v1'); let searchObj = { token, org_id }; @@ -79,4 +123,12 @@ document.addEventListener('DOMContentLoaded', async () => { }, }, }); +} + +document.addEventListener('DOMContentLoaded', async () => { + if (localStorage.getItem('useNewTheme') === 'true') { + atomicCoveo(); + } else { + legacyCoveo(); + } }); diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index f301905..9314a59 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -57,7 +57,7 @@ }); // swap out v1 and v2 elements - const v1ElementIds = ["sidebar", "footer", "toc", "api"] + const v1ElementIds = ["sidebar", "footer", "toc", "api", "search-v1"] v1ElementIds.forEach((elementId) => { const element = document.getElementById(elementId); @@ -170,9 +170,10 @@