Skip to content

feat: Enable Modals in Header/Footer #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions blocks/header/header.css
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,13 @@ header nav#nav .nav-tools {
grid-area: tools;
}

header nav#nav .nav-tools .button {
background: none;
border: none;
padding: 10px;
margin: 0;
}

/* breadcrumbs */
header .breadcrumbs {
display: none;
Expand Down
8 changes: 4 additions & 4 deletions blocks/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ function clearSearchResults(block) {

function clearSearch(block) {
clearSearchResults(block);
if (window.history.pushState) {
if (window.history.replaceState) {
const url = new URL(window.location.href);
url.search = '';
searchParams.delete('q');
window.history.pushState({}, '', url.toString());
window.history.replaceState({}, '', url.toString());
}
}

Expand Down Expand Up @@ -191,10 +191,10 @@ function filterData(searchTerms, data) {
async function handleSearch(e, block, config) {
const searchValue = e.target.value;
searchParams.set('q', searchValue);
if (window.history.pushState) {
if (window.history.replaceState) {
const url = new URL(window.location.href);
url.search = searchParams.toString();
window.history.pushState({}, '', url.toString());
window.history.replaceState({}, '', url.toString());
}

if (searchValue.length < 3) {
Expand Down
8 changes: 5 additions & 3 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ async function loadFonts() {
}
}

function autolinkModals(main) {
main.addEventListener('click', async (e) => {
function autolinkModals(element) {
element.addEventListener('click', async (e) => {
const origin = e.target.closest('a');

if (origin && origin.href && origin.href.includes('/modals/')) {
Expand All @@ -62,7 +62,6 @@ function autolinkModals(main) {
function buildAutoBlocks(main) {
try {
buildHeroBlock(main);
autolinkModals(main);
} catch (error) {
// eslint-disable-next-line no-console
console.error('Auto Blocking failed', error);
Expand Down Expand Up @@ -93,6 +92,7 @@ async function loadEager(doc) {
if (getMetadata('breadcrumbs').toLowerCase() === 'true') {
document.body.classList.add('breadcrumbs-enabled');
}

const main = doc.querySelector('main');
if (main) {
decorateMain(main);
Expand All @@ -115,6 +115,8 @@ async function loadEager(doc) {
* @param {Element} doc The container element
*/
async function loadLazy(doc) {
autolinkModals(doc);

const main = doc.querySelector('main');
await loadBlocks(main);

Expand Down