From fd18755c79450681dd226b914ef61459bcab4b9a Mon Sep 17 00:00:00 2001 From: Daan Kauwenberg Date: Wed, 10 Oct 2018 16:15:22 +0200 Subject: [PATCH 1/2] Check for anchors in parent instead of only the event.target --- src/theme/scripts/router.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/theme/scripts/router.js b/src/theme/scripts/router.js index 243f6c8..7d0cc7a 100644 --- a/src/theme/scripts/router.js +++ b/src/theme/scripts/router.js @@ -34,8 +34,10 @@ class Router { } async _onLinkClick(event) { - if(event.target.tagName !== 'A') return; - const link = new URL(event.target.href); + // See if what is clicked has an anchor as parent or is a link itself and create an URL of it + const link = event.target.closest('a') ? new URL(event.target.closest('a').href) : null; + if (!link) return; + // If it’s an external link, just navigate. if(link.host !== this._hostname) { return; From 35b9f0b169584b524a68a088c4e265c1a7419a88 Mon Sep 17 00:00:00 2001 From: Daan Kauwenberg Date: Thu, 11 Oct 2018 14:00:42 +0200 Subject: [PATCH 2/2] Only search dom for closest A once --- src/theme/scripts/router.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/theme/scripts/router.js b/src/theme/scripts/router.js index 7d0cc7a..9e391f7 100644 --- a/src/theme/scripts/router.js +++ b/src/theme/scripts/router.js @@ -34,9 +34,10 @@ class Router { } async _onLinkClick(event) { - // See if what is clicked has an anchor as parent or is a link itself and create an URL of it - const link = event.target.closest('a') ? new URL(event.target.closest('a').href) : null; - if (!link) return; + // See if what is clicked has an anchor as parent or is a link itself. If so create URL otherwise return. + const linkElement = event.target.closest('a'); + if (!linkElement) return; + const link = new URL(linkElement.href); // If it’s an external link, just navigate. if(link.host !== this._hostname) {