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

imagecta link fix #41

Merged
merged 4 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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: 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');
kailasnadh790 marked this conversation as resolved.
Show resolved Hide resolved
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
7 changes: 6 additions & 1 deletion cigaradvisor/styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,9 @@ main .section[data-layout="50/50"] .imagecta.block > a{
main .section[data-layout="50/50"] .imagecta.block>a img {
border: 1px solid #000;
}
}

/* removing border for 2 column videos section */
main .two-column-section[data-layout="50/50"] .imagecta.block>a img {
kailasnadh790 marked this conversation as resolved.
Show resolved Hide resolved
border: none;
}
}