Skip to content

Commit

Permalink
refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
kailasnadh790 committed Dec 6, 2023
1 parent 43ccb2e commit b17e43b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 115 deletions.
62 changes: 0 additions & 62 deletions cigaradvisor/blocks/two-col-grid/two-col-grid.css

This file was deleted.

23 changes: 0 additions & 23 deletions cigaradvisor/blocks/two-col-grid/two-col-grid.js

This file was deleted.

44 changes: 14 additions & 30 deletions cigaradvisor/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,37 +35,21 @@ function buildHeroBlock(main) {
* @param {Element} main The container element
*/
function buildTwoColumnGrid(main) {
main.querySelectorAll(':scope > div div.section-metadata').forEach((metadata) => {
let style;
[...metadata.querySelectorAll(':scope > div')].every((div) => {
const match = div.children[1]?.textContent.toLowerCase().trim().match(/50\/50/i);
if (div.children[0]?.textContent.toLowerCase().trim() === 'layout' && match) {
style = match[0].replaceAll(/\s/g, '-');
return false;
main.querySelectorAll(':scope > .section[data-layout="50/50"]').forEach((section) => {
const leftDiv = document.createElement('div');
leftDiv.classList.add('left-grid');
const rightDiv = document.createElement('div');
rightDiv.classList.add('right-grid');
let current = leftDiv;
[...section.children].forEach((child) => {
if (child.classList.contains('separator-wrapper')) {
current = rightDiv;
child.remove();
return;
}
return true;
current.append(child);
});
if (style) {
const section = metadata.parentElement;
const left = [];
const right = [];
let flag = true;
[...section.children].forEach((child) => {
if (child.classList.contains('separator')) {
flag = false;
}
if (!child.classList.contains('section-metadata') && !child.classList.contains('separator')) {
if (flag) {
left.push(child);
} else {
right.push(child);
}
}
});
const block = buildBlock('two-col-grid', [[{ elems: left }, { elems: right }]]);
block.classList.add(style);
section.prepend(block);
}
section.append(leftDiv, rightDiv);
});
}

Expand All @@ -88,7 +72,6 @@ async function loadFonts() {
function buildAutoBlocks(main) {
try {
buildHeroBlock(main);
buildTwoColumnGrid(main);
} catch (error) {
// eslint-disable-next-line no-console
console.error('Auto Blocking failed', error);
Expand All @@ -107,6 +90,7 @@ export function decorateMain(main) {
buildAutoBlocks(main);
decorateSections(main);
decorateBlocks(main);
buildTwoColumnGrid(main);
}

/**
Expand Down
53 changes: 53 additions & 0 deletions cigaradvisor/styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,57 @@ a:hover {

a:active, a:hover {
outline-width: 0;
}

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

@media screen and (max-width: 600px){
main .section[data-layout="50/50"]{
width: 100%;
flex-direction: column;
}
}

main .section[data-layout="50/50"] > div {
display: flex;
flex-basis: 100%;
flex-direction: column;
}

main .section[data-layout="50/50"] .left-grid > div{
padding: 10px;
}

main .section[data-layout="50/50"] .right-grid > div{
padding: 10px;
}

main .section[data-layout="50/50"] .imagecta-wrapper{
display: flex;
flex-basis: 100%;
}

main .section[data-layout="50/50"] .imagecta.block{
display: flex;
flex-basis: 100%;
}

main .section[data-layout="50/50"] .imagecta.block > a{
flex-basis: 100%;
}

@media screen and (min-width: 1200px) {
main .section[data-layout="50/50"] .imagecta.block>a img {
border: 1px solid #000;
}
}

0 comments on commit b17e43b

Please sign in to comment.