diff options
author | silverwind <me@silverwind.io> | 2024-03-09 00:21:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-08 23:21:45 +0000 |
commit | baeb2511741aa70d24a48fd46db936b52be9d9dd (patch) | |
tree | 0e8d56943a99cb1f9f2f00979e1809374e43aee0 /web_src/js | |
parent | 82e102f8b09faf1ac2786ccad36d4a20fcb392b8 (diff) | |
download | gitea-baeb2511741aa70d24a48fd46db936b52be9d9dd.tar.gz gitea-baeb2511741aa70d24a48fd46db936b52be9d9dd.zip |
Use more specific selector for `name` links (#29679)
Followup https://github.com/go-gitea/gitea/pull/29305. As per discussion
in https://github.com/go-gitea/gitea/pull/29666#discussion_r1517506422,
make this selector only search in the current `.markup` document, as
there can be multiples displayed at the same time.
@DanielMatiasCarvalho maybe you can review.
Diffstat (limited to 'web_src/js')
-rw-r--r-- | web_src/js/markup/anchors.js | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/web_src/js/markup/anchors.js b/web_src/js/markup/anchors.js index 03934ea215..6cf83eb428 100644 --- a/web_src/js/markup/anchors.js +++ b/web_src/js/markup/anchors.js @@ -39,7 +39,7 @@ export function initMarkupAnchors() { if (!href.startsWith('#user-content-')) continue; const originalId = href.replace(/^#user-content-/, ''); a.setAttribute('href', `#${encodeURIComponent(originalId)}`); - if (document.getElementsByName(originalId).length !== 1) { + if (a.closest('.markup').querySelectorAll(`a[name="${originalId}"]`).length !== 1) { a.addEventListener('click', (e) => { scrollToAnchor(e.currentTarget.getAttribute('href'), false); }); |