Skip to content
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

Feature/404 #79

Merged
merged 8 commits into from
Jan 18, 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: 5 additions & 2 deletions 404.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
</script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:title" content="Page not found">
<script src="/cigaradvisor/scripts/cigaradvisor/scripts.js" type="module" crossorigin="use-credentials"></script>
<script src="/cigaradvisor/scripts/scripts.js" type="module" crossorigin="use-credentials"></script>
<script type="module">
import { sampleRUM } from '/cigaradvisor/scripts/aem.js';
import { loadFragment } from '/cigaradvisor/blocks/fragment/fragment.js';

window.addEventListener('load', () => {
window.addEventListener('load', async() => {
if (document.referrer) {
const { origin, pathname } = new URL(document.referrer);
if (origin === window.location.origin) {
Expand All @@ -27,6 +28,8 @@
}
}
sampleRUM('404', { source: document.referrer, target: window.location.href });
const main = document.querySelector('main');
main.replaceWith(await loadFragment('/cigaradvisor/fragments/404'));
});
</script>
<link rel="stylesheet" href="/cigaradvisor/styles/styles.css">
Expand Down
30 changes: 30 additions & 0 deletions cigaradvisor/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,35 @@ function buildArticleHeader(mainEl) {
mainEl.prepend(div);
}

/**
* Builds three column grid.
* @param {Element} main The container element
*/
function buildThreeColumnGrid(main) {
main.querySelectorAll(':scope > .section[data-layout="3-column"]').forEach((section) => {
const leftDiv = document.createElement('div');
leftDiv.classList.add('left-grid');
const centerDiv = document.createElement('div');
centerDiv.classList.add('center-grid');
const rightDiv = document.createElement('div');
rightDiv.classList.add('right-grid');
let current = leftDiv;
[...section.children].forEach((child) => {
if (child.classList.contains('separator-wrapper')) {
if (current === centerDiv) {
current = rightDiv;
} else {
current = centerDiv;
}
child.remove();
return;
}
current.append(child);
});
section.append(leftDiv, centerDiv, rightDiv);
});
}

/**
* Builds two column grid.
* @param {Element} main The container element
Expand Down Expand Up @@ -157,6 +186,7 @@ export function decorateMain(main) {
decorateSections(main);
decorateBlocks(main);
buildTwoColumnGrid(main);
buildThreeColumnGrid(main);
}

/**
Expand Down
36 changes: 36 additions & 0 deletions cigaradvisor/styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,42 @@ main .section[data-layout="50/50"] .right-grid > div {
padding: 10px;
}

/* Three-column grid */
main .section[data-layout="3-column"] {
padding-left: 0;
padding-right: 0;
width: 100%;
margin-left: auto;
margin-right: auto;
max-width: 1080px;
box-sizing: border-box;
display: flex;
}

main .section[data-layout="3-column"] ul {
list-style-type: disc;
}

/* stylelint-disable-next-line no-descending-specificity */
main .section[data-layout="3-column"] > div {
display: flex;
flex: 1;
flex-direction: column;
}

main .section[data-layout="3-column"] > .left-grid {
flex: 0 0 25%;
}

main .section[data-layout="3-column"] > .center-grid, main .section[data-layout="3-column"] > .right-grid {
flex: 0 0 37.5%;
}

/* stylelint-disable-next-line no-descending-specificity */
main .section[data-layout="3-column"] * > div {
padding: 2px;
}

.icon > img {
width: var(--icon-size);
height: var(--icon-size);
Expand Down