Skip to content

Commit

Permalink
feat(theme): override target="_blank" behavior (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin authored Sep 23, 2023
1 parent 6a45109 commit f16594a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions frontend/src/svg_utils.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,23 @@ window.typstProcessSvg = function (docRoot) {
}

docRoot.addEventListener('click', event => {
const origin = event.target.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;
}
return;
}

let elem = event.target;
while (elem) {
const span = elem.getAttribute('data-span');
Expand Down

0 comments on commit f16594a

Please sign in to comment.