Skip to content

Commit

Permalink
imagecta link fix (#41)
Browse files Browse the repository at this point in the history
* imagecta link fix

* refactored

* Update styles.css

* refactoring code
  • Loading branch information
kailasnadh790 authored Dec 11, 2023
1 parent ec00e88 commit 116744d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 20 deletions.
25 changes: 25 additions & 0 deletions cigaradvisor/blocks/imagecta/imagecta.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,28 @@
object-fit: cover;
object-position: center;
}

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

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

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

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

/* removing border for 2 column videos section */
.two-column-section[data-layout="50/50"] .imagecta.block>a img {
border: none;
}
}
7 changes: 6 additions & 1 deletion cigaradvisor/blocks/imagecta/imagecta.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isExternal } from '../../scripts/scripts.js';

export default async function decorate(block) {
const children = [];
const anchor = document.createElement('a');
Expand All @@ -7,7 +9,10 @@ export default async function decorate(block) {
picture.style.paddingBottom = `${ratio}%`;
anchor.style.maxWidth = `${img.width}px`;
anchor.append(picture);
anchor.setAttribute('href', block.querySelector('a').getAttribute('href'));
const link = block.querySelector('a').getAttribute('href');
anchor.setAttribute('href', link);
anchor.setAttribute('target', isExternal(link) ? '_blank' : '_self');
anchor.setAttribute('title', img.alt);
children.push(anchor);
block.replaceChildren(...children);
}
9 changes: 9 additions & 0 deletions cigaradvisor/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ export function decorateMain(main) {
buildTwoColumnGrid(main);
}

export function isExternal(path) {
try {
const url = new URL(path);
return window.location.hostname !== url.hostname;
} catch (error) {
return false;
}
}

/**
* Loads everything needed to get to LCP.
* @param {Element} doc The container element
Expand Down
19 changes: 0 additions & 19 deletions cigaradvisor/styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,3 @@ 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 116744d

Please sign in to comment.