Skip to content

Commit 02b3c7b

Browse files
authored
Wider support for Coveo on Mobile + Edge cases (#201)
* feat: Support coveo on mobile + show in header * feat: Support on mobile fully + handle all bugs * feat: Removed unneeded JS + moved to CSS
1 parent f24df47 commit 02b3c7b

File tree

7 files changed

+91
-14
lines changed

7 files changed

+91
-14
lines changed

assets/css/v2/style.css

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,34 @@ header {
140140
.header-container {
141141
display: flex;
142142
flex-direction: row;
143+
flex-wrap: wrap;
143144
justify-content: space-between;
144145
align-items: center;
145146
width: 100%;
147+
148+
> ul {
149+
padding: 0;
150+
}
151+
152+
@media (max-width: 700px) {
153+
a,
154+
ul {
155+
width: 50%;
156+
}
157+
158+
li {
159+
float: right;
160+
}
161+
162+
div {
163+
order: 3;
164+
width: 100%;
165+
166+
#search-standalone-header {
167+
margin-top: 1rem;
168+
}
169+
}
170+
}
146171
}
147172

148173
ul {
@@ -255,6 +280,7 @@ nav {
255280
grid-template-columns: var(--text-content-width-iphone-13) 1fr;
256281
grid-template-rows: var(--breadcrumb-max-height) 1fr;
257282
z-index: 1;
283+
margin-top: 2rem;
258284
}
259285

260286
.docs-container {
@@ -363,7 +389,6 @@ nav {
363389
--side-gutter-width
364390
);
365391
column-gap: var(--component-gap);
366-
margin-top: 2rem;
367392
}
368393

369394
.content-layout .side-gutter {
@@ -445,6 +470,9 @@ atomic-search-interface {
445470
height: fit-content;
446471
margin-bottom: 2rem;
447472
margin-top: 2rem;
473+
}
474+
475+
#search-standalone-sidebar {
448476
min-height: 54px;
449477
max-height: 54px;
450478
}
@@ -520,6 +548,30 @@ atomic-search-layout atomic-layout-section[section="search"] {
520548
z-index: 9999;
521549
}
522550

551+
header atomic-search-interface {
552+
/* Hide by default */
553+
display: none;
554+
}
555+
556+
body:not(:has(.main-layout)) header atomic-search-interface {
557+
/* Show on landing pages */
558+
display: block;
559+
}
560+
561+
@media (max-width: 1184px) {
562+
/* Show on pages with sidebar if it is hidden */
563+
body:has(.sidebar-layout) header atomic-search-interface {
564+
display: block;
565+
}
566+
}
567+
568+
@media (max-width: 1023px) {
569+
/* Show on search page with facet if it is hidden */
570+
body:has(atomic-search-layout) header atomic-search-interface {
571+
display: block;
572+
}
573+
}
574+
523575
/* Sidebar */
524576
.sidebar {
525577
display: flex;

assets/js/coveo.js

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ async function getsearchObj() {
2121
}
2222

2323
async 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,14 @@ 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+
42+
if (searchPageInterface) {
43+
await searchPageInterface.initialize({
4044
accessToken: token,
4145
organizationId: org_id,
4246
analytics: { analyticsMode: 'legacy' },
@@ -48,10 +52,27 @@ async function atomicCoveo() {
4852
return request;
4953
},
5054
});
51-
searchInterface.executeFirstSearch();
55+
await searchPageInterface.executeFirstSearch();
56+
} else {
57+
if (sidebar) {
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();
71+
}
5272
}
5373

54-
await searchInterfaceStandalone.initialize({
74+
/* Initialize the header searchbar*/
75+
await searchBarHeader.initialize({
5576
accessToken: token,
5677
organizationId: org_id,
5778
analytics: { analyticsMode: 'legacy' },
@@ -63,7 +84,8 @@ async function atomicCoveo() {
6384
return request;
6485
},
6586
});
66-
searchInterfaceStandalone.executeFirstSearch();
87+
88+
await searchBarHeader.executeFirstSearch();
6789
}
6890

6991
async function legacyCoveo() {

layouts/_default/baseof.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161

6262
v1ElementIds.forEach((elementId) => {
6363
const element = document.getElementById(elementId);
64-
console.log(element)
6564
if (element !== null) {
6665
element.style.display = isNewTheme ? "none" : "";
6766
}

layouts/_default/docs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
{{ end }}
1616

1717
<section class="main-layout">
18-
<div class="sidebar-layout">
18+
<div class="sidebar-layout" id="sidebar-layout">
1919
<nav data-mf="true" id="sidebar-v2" class="sidebar" style="display:none;">
2020
{{ partial "sidebar-v2.html" . }}
2121
</nav>

layouts/partials/header.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
</a>
77
{{ if ( not ( in .Site.Params.buildtype "package" ) ) }}
88
<div class="navbar navbar-nav">
9-
<!-- Standalone search box. -->
9+
<!-- Standalone search box. -->
1010
<div id="searchbox">
1111
<!--div class="CoveoAnalytics" data-search-hub="HUB_ES_Nginx_Docs_And_Org"></div-->
1212
<div class="CoveoSearchbox" data-placeholder='Search NGINX Docs...'></div>
1313
</div>
14+
<atomic-search-interface id="search-standalone-header" data-mf="true" style="display:none;">
15+
<atomic-search-box redirection-url="/search.html">
16+
</atomic-search-box>
17+
</atomic-search-interface>
1418
</div>
1519
{{ end }}
1620
{{ if ( in .Site.Params.buildtype "package" ) }}

layouts/partials/sidebar-v2.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
{{ $productIdentifier := index ((split $relPermalink "/")) 1 }}
2121
{{ $productName := index $productMap $productIdentifier }}
2222

23-
<atomic-search-interface id="search-standalone" data-mf="true" style="display:none;">
23+
<atomic-search-interface id="search-standalone-sidebar" data-mf="true" style="display:none;">
2424
<atomic-search-box redirection-url="/search.html">
2525
</atomic-search-box>
2626
</atomic-search-interface>

layouts/search/single.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121

122122
<!-- Facet Section -->
123123
<atomic-layout-section section="facets">
124-
<atomic-search-box></atomic-search-box>
124+
<atomic-search-box id="search-standalone-searchpage"></atomic-search-box>
125125
<atomic-facet field="f5_product" label="Show by product"></atomic-facet>
126126
<atomic-refine-toggle></atomic-refine-toggle>
127127
</atomic-layout-section>

0 commit comments

Comments
 (0)