Skip to content

Commit

Permalink
feat(theme): more clever impl
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin committed Sep 23, 2023
1 parent bcb9917 commit 83978f8
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions frontend/src/svg_utils.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 83978f8

Please sign in to comment.