From 83978f88342e6567ad195ed64c498ec89b69b0f6 Mon Sep 17 00:00:00 2001 From: Myriad-Dreamin Date: Sat, 23 Sep 2023 14:39:13 +0800 Subject: [PATCH] feat(theme): more clever impl --- frontend/src/svg_utils.cjs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/frontend/src/svg_utils.cjs b/frontend/src/svg_utils.cjs index fcbfa8e..e53a4c7 100644 --- a/frontend/src/svg_utils.cjs +++ b/frontend/src/svg_utils.cjs @@ -137,24 +137,18 @@ window.typstProcessSvg = function (docRoot) { } docRoot.addEventListener('click', event => { - const origin = event.target.closest(`a`); + let elem = event.target; + const origin = elem.closest(`a`); - if (origin && origin.getAttribute('onclick') !== undefined) { - // stop the browser automatically opening a new tab - event.preventDefault(); - - // console.log(origin, origin.href); - - // do whatever you want with the url - if (typeof SVGAnimatedString !== 'undefined' && origin.href instanceof SVGAnimatedString) { - window.location = origin.href.baseVal; - } else { - window.location = origin.href; + if (origin && origin.getAttribute('onclick') === null) { + let target = origin.getAttribute('target'); + if (target === '_blank') { + // remove the target attribute + origin.removeAttribute('target'); } return; } - let elem = event.target; while (elem) { const span = elem.getAttribute('data-span'); if (span) {