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/image cta #31

Merged
merged 12 commits into from
Dec 4, 2023
21 changes: 21 additions & 0 deletions cigaradvisor/blocks/imagecta/imagecta.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.imagecta.block > a {
display: block;
margin: 0 auto;
}

.imagecta.block > a picture {
display: block;
position: relative;
width: 100%;
height: 100%;
margin: 0 auto;
}

.imagecta.block > a picture > img {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
object-fit: contain;
object-position: center;
}
13 changes: 13 additions & 0 deletions cigaradvisor/blocks/imagecta/imagecta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default async function decorate(block) {
const children = [];
const anchor = document.createElement('a');
const picture = block.querySelector('picture');
const img = picture.querySelector('img');
const ratio = (parseInt(img.height, 10) / parseInt(img.width, 10)) * 100;
picture.style.paddingBottom = `${ratio}%`;
anchor.style.maxWidth = `${img.width}px`;
anchor.append(picture);
anchor.setAttribute('href', block.querySelector('a').getAttribute('href'));
children.push(anchor);
block.replaceChildren(...children);
}