Skip to content

Commit

Permalink
Merge branch 'main' into bug/hero-gradient
Browse files Browse the repository at this point in the history
  • Loading branch information
bstopp authored Dec 19, 2023
2 parents e0a71e2 + a4fb9cd commit 3bbfbde
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
8 changes: 6 additions & 2 deletions blocks/cards/cards.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
padding: 0;
}

.cards.block.cards-1-cols .cards-list .card-image {
margin-bottom: 25px;
}


.cards.block .cards-list .cards-item .card-image {
position: relative;
display: flex;
Expand All @@ -47,12 +52,11 @@
position: relative;
height: 100%;
width: 100%;
padding-bottom: 66%;
}

.cards.block .cards-list .cards-item .card-image img {
position: absolute;
top: 0;
bottom: 0;
left: 0;
object-fit: cover;
object-position: center;
Expand Down
14 changes: 13 additions & 1 deletion blocks/cards/cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function decorate(block) {
list.classList.add('cards-list');
block.append(list);

// add logic for check-list case
// add logic for checklist case
if (block.classList.contains('icons')) {
block.classList.add('cards-2-cols');
cards.forEach((row) => {
Expand All @@ -24,6 +24,7 @@ export default function decorate(block) {
list.append(row);
});
} else {
let ratio = 9999;
block.classList.add(`cards-${cards.length}-cols`);
cards.forEach((row) => {
row.className = 'cards-item';
Expand All @@ -32,13 +33,24 @@ export default function decorate(block) {
// update container for picture with label
div.classList.add('card-image');
const picture = div.querySelector('picture');
const img = picture.querySelector('img');
const tmp = (parseInt(img.height, 10) / parseInt(img.width, 10)) * 100;
if (tmp < ratio) {
ratio = tmp;
}
const paragraphElement = document.createElement(('p'));
paragraphElement.textContent = div.textContent.trim();
div.replaceChildren(picture, paragraphElement);
} else {
div.classList.add('card-body');
}
});
// Pad the picture with the smallest ratio image.
[...row.children].forEach((div) => {
if (div.querySelector('picture')) {
div.querySelector('picture').style.paddingBottom = `${ratio}%`;
}
});
list.append(row);
});
}
Expand Down
4 changes: 4 additions & 0 deletions blocks/separator/separator.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
border: none;
background: var(--platinum);
}

.separator.block.padded {
margin: 30px 0;
}
9 changes: 9 additions & 0 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ function decorateVideoLinks(main) {
});
}

function decorateImages(main) {
main.querySelectorAll('.section .default-content-wrapper picture').forEach((picture) => {
const img = picture.querySelector('img');
const ratio = (parseInt(img.height, 10) / parseInt(img.width, 10)) * 100;
picture.style.paddingBottom = `${ratio}%`;
});
}

/**
* Build Floating image block
* @param {Element} main The container element
Expand Down Expand Up @@ -252,6 +260,7 @@ export function decorateMain(main) {
decorateSections(main);
decorateBlocks(main);
decorateVideoLinks(main);
decorateImages(main);
}

/**
Expand Down
17 changes: 17 additions & 0 deletions styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,23 @@ main .section .default-content-wrapper h4 {
margin-bottom: 1.25em;
}

main .section .default-content-wrapper picture {
display: block;
position: relative;
height: 100%;
width: 100%;
}

main .section .default-content-wrapper picture img {
position: absolute;
height: 100%;
width: 100%;
left: 0;
bottom: 0;
object-fit: cover;
object-position: center;
}

/* common styles */
@keyframes spinner-spin {
0% { transform: rotate(0deg); }
Expand Down

0 comments on commit 3bbfbde

Please sign in to comment.