Skip to content

Commit

Permalink
Merge pull request #192 from hlxsites/maxed/perf
Browse files Browse the repository at this point in the history
performance fixes
  • Loading branch information
maxakuru authored Oct 6, 2023
2 parents d0d4dc7 + ac089e4 commit b859a62
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 108 deletions.
1 change: 1 addition & 0 deletions blocks/card-carousel/card-carousel.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
margin: 0 auto;
max-width: calc(1032px + var(--padding--mobile) + var(--padding--mobile));
padding: var(--padding--mobile);
overflow: hidden;
}

.card-carousel .splide__track {
Expand Down
2 changes: 1 addition & 1 deletion blocks/header/header.css
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@
z-index: 100;
top: 0;
height: 0;
width: 100%;
width: 100vw;
transition: opacity var(--action-ease-duration) var(--action-ease-function);
visibility: hidden;
display: flex;
Expand Down
49 changes: 29 additions & 20 deletions blocks/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import {
isMobile,
parseFragment,
render,
renderBreadCrumbs,
} from '../../scripts/scripts.js';
import '../language-selector/language-selector.js';
import '../search-bar/search-bar.js';
import '../theme-toggle/theme-toggle.js';

// <search-bar data-default-option="all"></search-bar>
const TEMPLATE = /* html */ `
Expand Down Expand Up @@ -372,16 +368,19 @@ function addEventListeners(block) {
);

/* Search */
const emitLoadSearch = (() => {
let sent = false;
return () => {
if (sent) return false;
sent = true;
store.emit('load:search');
return true;
};
})();
const searchButtonOpen = desktopNav.querySelector('.nav-search-button');
const searchButtonClose = searchPanel.querySelector('.search-panel-close');

// searchButtonOpen.addEventListener(
// "mouseenter",
// () => {
// import("../search-bar/search-bar.js");
// },
// { once: true }
// );
searchButtonOpen.addEventListener('mouseenter', emitLoadSearch, { once: true });

const focusSearchInput = () => {
// Check for searchbar
Expand All @@ -395,15 +394,23 @@ function addEventListeners(block) {
}
};

const openSearch = () => {
// delay to load search before opening first time
const delay = emitLoadSearch('load:search') ? 150 : 1;
setTimeout(() => {
searchPanel.classList.add('active');

// Focus on search input
focusSearchInput();
}, delay);
};

window.addEventListener('keydown', (e) => {
const { key } = e;
const searchIsActive = searchPanel.classList.contains('active');

if (key === '/' && !searchIsActive) {
searchPanel.classList.add('active');

// Focus on search input
focusSearchInput();
openSearch();
}

if (key === 'Escape' && searchIsActive) {
Expand All @@ -412,10 +419,7 @@ function addEventListeners(block) {
});

searchButtonOpen.addEventListener('click', () => {
searchPanel.classList.add('active');

// Focus on search input
focusSearchInput();
openSearch();
});

searchButtonClose.addEventListener('click', () => {
Expand Down Expand Up @@ -626,6 +630,11 @@ export default async function decorate(block) {
if (!isMobile()) {
// renderBreadCrumbs();
} else {
store.once('delayed:loaded', renderBreadCrumbs);
// store.once('delayed:loaded', renderBreadCrumbs);
}

// load custom elements
import('../language-selector/language-selector.js');
import('../search-bar/search-bar.js');
import('../theme-toggle/theme-toggle.js');
}
6 changes: 3 additions & 3 deletions blocks/hero-search/hero-search.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 62 additions & 12 deletions blocks/search-bar/search-bar.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,56 @@ search-bar {
display: flex;
}

.search-bar #coveo-searchbox #placeholder-searchbox {
flex-grow: 1;
display: flex;
}

.search-bar #coveo-searchbox #placeholder-searchbox div {
border-top: 1px solid var(--search-border-color);
border-bottom: 1px solid var(--search-border-color);
border-left: 1px solid var(--search-border-color);
border-radius: 0;
border-top-left-radius: var(--search-border-radius);
border-bottom-left-radius: var(--search-border-radius);
height: var(--search-height);
width: 43px;
min-width: 43px;
background: var(--search-background-color);
display: flex;
justify-content: space-around;
align-items: center;
}

.search-bar #coveo-searchbox #placeholder-searchbox input {
background: var(--search-background-color);
color: var(--search-text-color);
font-family: var(--body-font-family);
font-size: var(--control-font-size--sm);
line-height: var(--control-line-height--sm);
padding: 13px 16px 11px 1px;
padding-right: var(--spacing--4);
border: none;
resize: none;
outline: 0;
margin: 0;
border-top: 1px solid var(--search-border-color);
border-bottom: 1px solid var(--search-border-color);
border-radius: 0;
height: var(--search-height);
margin-left: -1px;
flex-grow: 1;
}

.search-bar #coveo-searchbox #placeholder-searchbox input::placeholder {
color: var(--search-placeholder);
padding-top: 10px;
}

.search-bar.coveo-ready #coveo-searchbox #placeholder-searchbox {
display: none;
}

.search-bar #coveo-searchbox .magic-box {
border: none;
border-radius: 0;
Expand Down Expand Up @@ -247,22 +297,22 @@ search-bar {
}

.search-bar
.magic-box.magic-box-hasFocus
.magic-box-suggestions.magic-box-hasSuggestion
.coveo-magicbox-suggestions,
.magic-box.magic-box-hasFocus
.magic-box-suggestions.magic-box-hasSuggestion
.coveo-magicbox-suggestions,
.search-bar
.magic-box.magic-box-hasFocus
.magic-box-suggestions.magic-box-hasSuggestion
.coveo-suggestion-container,
.magic-box.magic-box-hasFocus
.magic-box-suggestions.magic-box-hasSuggestion
.coveo-suggestion-container,
.search-bar .magic-box .magic-box-suggestions .coveo-magicbox-suggestions {
border: none;
}

.search-bar .dropdown-content,
.search-bar
.magic-box
.magic-box-suggestions.magic-box-hasSuggestion
.coveo-magicbox-suggestions {
.magic-box
.magic-box-suggestions.magic-box-hasSuggestion
.coveo-magicbox-suggestions {
background: var(--search-background-color);
border-radius: var(--search-autosuggest-border-radius);
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.08);
Expand All @@ -283,9 +333,9 @@ search-bar {

.search-bar .dropdown-content a:not(:last-child),
.search-bar
.magic-box
.magic-box-suggestions
.magic-box-suggestion:not(:last-child) {
.magic-box
.magic-box-suggestions
.magic-box-suggestion:not(:last-child) {
margin-bottom: var(--spacing--1);
}

Expand Down
Loading

0 comments on commit b859a62

Please sign in to comment.