Skip to content

Commit 33e2e9f

Browse files
committed
feat: Support on mobile fully + handle all bugs
1 parent 5f554d3 commit 33e2e9f

File tree

4 files changed

+84
-22
lines changed

4 files changed

+84
-22
lines changed

assets/css/v2/style.css

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,34 @@ header {
9898
.header-container {
9999
display: flex;
100100
flex-direction: row;
101+
flex-wrap: wrap;
101102
justify-content: space-between;
102103
align-items: center;
103104
width: 100%;
105+
106+
> ul {
107+
padding: 0;
108+
}
109+
110+
@media (max-width: 700px) {
111+
a,
112+
ul {
113+
width: 50%;
114+
}
115+
116+
li {
117+
float: right;
118+
}
119+
120+
div {
121+
order: 3;
122+
width: 100%;
123+
124+
#search-standalone-header {
125+
margin-top: 1rem;
126+
}
127+
}
128+
}
104129
}
105130

106131
ul {
@@ -213,6 +238,7 @@ nav {
213238
grid-template-columns: var(--text-content-width-iphone-13) 1fr;
214239
grid-template-rows: var(--breadcrumb-max-height) 1fr;
215240
z-index: 1;
241+
margin-top: 2rem;
216242
}
217243

218244
.docs-container {
@@ -320,7 +346,6 @@ nav {
320346
--side-gutter-width
321347
);
322348
column-gap: var(--component-gap);
323-
margin-top: 2rem;
324349
}
325350

326351
.content-layout .side-gutter {
@@ -402,6 +427,9 @@ atomic-search-interface {
402427
height: fit-content;
403428
margin-bottom: 2rem;
404429
margin-top: 2rem;
430+
}
431+
432+
#search-standalone-sidebar {
405433
min-height: 54px;
406434
max-height: 54px;
407435
}

assets/js/coveo.js

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ async function atomicCoveo() {
3838
const searchBarHeader = document.querySelector('#search-standalone-header');
3939
const searchBarSidebar = document.querySelector('#search-standalone-sidebar');
4040
const sidebar = document.querySelector('#sidebar-layout');
41-
let searchbar;
4241

4342
if (searchPageInterface) {
4443
await searchPageInterface.initialize({
@@ -53,29 +52,42 @@ async function atomicCoveo() {
5352
return request;
5453
},
5554
});
56-
searchPageInterface.executeFirstSearch();
55+
await searchPageInterface.executeFirstSearch();
5756
} else {
58-
// If there is a searchbar, only initialize the searchbar for the sidebar.
5957
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();
6371
}
72+
}
6473

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);
7383

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();
7991
}
8092

8193
async function legacyCoveo() {
@@ -146,3 +158,26 @@ document.addEventListener('DOMContentLoaded', async () => {
146158
legacyCoveo();
147159
}
148160
});
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+
});

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/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)