From 296b6376e33c55536f50677672536219f01c4023 Mon Sep 17 00:00:00 2001 From: Emma Indal Date: Thu, 10 Sep 2020 12:05:22 +0200 Subject: [PATCH 01/13] fix unclickable external links (#2396) --- .../src/reader/transformers/addLinkClickListener.ts | 6 ++++-- plugins/techdocs/src/reader/transformers/rewriteDocLinks.ts | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/techdocs/src/reader/transformers/addLinkClickListener.ts b/plugins/techdocs/src/reader/transformers/addLinkClickListener.ts index 93e4b67a1b..3566b403a2 100644 --- a/plugins/techdocs/src/reader/transformers/addLinkClickListener.ts +++ b/plugins/techdocs/src/reader/transformers/addLinkClickListener.ts @@ -26,9 +26,11 @@ export const addLinkClickListener = ({ return dom => { Array.from(dom.getElementsByTagName('a')).forEach(elem => { elem.addEventListener('click', (e: MouseEvent) => { - e.preventDefault(); const target = e.target as HTMLAnchorElement; - if (target?.getAttribute('href')) { + const href = target?.getAttribute('href'); + if (!href) return; + if (!href.match(/^https?:\/\//i)) { + e.preventDefault(); onClick(e, target.getAttribute('href')!); } }); diff --git a/plugins/techdocs/src/reader/transformers/rewriteDocLinks.ts b/plugins/techdocs/src/reader/transformers/rewriteDocLinks.ts index 856bb40f0f..7b0c23c3e3 100644 --- a/plugins/techdocs/src/reader/transformers/rewriteDocLinks.ts +++ b/plugins/techdocs/src/reader/transformers/rewriteDocLinks.ts @@ -27,6 +27,10 @@ export const rewriteDocLinks = (): Transformer => { .forEach((elem: T) => { const elemAttribute = elem.getAttribute(attributeName); if (elemAttribute) { + // if link is external, add target to open in a new window or tab + if (elemAttribute.match(/^https?:\/\//i)) { + elem.setAttribute('target', '_blank'); + } const normalizedWindowLocation = window.location.href.endsWith('/') ? window.location.href : `${window.location.href}/`; From 3bfa0d7832cab62ee2f89d945f3df6157a1f2b29 Mon Sep 17 00:00:00 2001 From: Emma Indal Date: Thu, 10 Sep 2020 12:50:58 +0200 Subject: [PATCH 02/13] IconLinkVertical component to accept disabled prop --- .../src/components/AboutCard/AboutCard.tsx | 3 +++ .../IconLinkVertical/IconLinkVertical.tsx | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/plugins/catalog/src/components/AboutCard/AboutCard.tsx b/plugins/catalog/src/components/AboutCard/AboutCard.tsx index 0ab918dd6f..939449f719 100644 --- a/plugins/catalog/src/components/AboutCard/AboutCard.tsx +++ b/plugins/catalog/src/components/AboutCard/AboutCard.tsx @@ -102,6 +102,9 @@ export function AboutCard({ entity }: AboutCardProps) {