Skip to content

Commit

Permalink
imagecta link fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kailasnadh790 committed Dec 7, 2023
1 parent 95bf47f commit 07b8b33
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 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,9 @@ 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));
children.push(anchor);
block.replaceChildren(...children);
}
6 changes: 6 additions & 0 deletions cigaradvisor/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ export function decorateMain(main) {
buildTwoColumnGrid(main);
}

export function isExternal(url) {
const anchor = document.createElement('a');
anchor.href = url;
return (anchor.hostname !== window.location.hostname) ? '_blank' : '_self';
}

/**
* Loads everything needed to get to LCP.
* @param {Element} doc The container element
Expand Down

0 comments on commit 07b8b33

Please sign in to comment.