diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-11-21 07:22:15 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-11-21 07:50:14 -0400 |
commit | 745eb45531afb233a49433b18e3095238eb41b84 (patch) | |
tree | d1e3367b61316cca7ba9a0b616f36a4f88b2453d /src/static | |
parent | c9847299d6a31b5fb39f82f80c92e80d53c44234 (diff) |
client: internal beforeHashLinkScrolls listener
Diffstat (limited to 'src/static')
-rw-r--r-- | src/static/client3.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/static/client3.js b/src/static/client3.js index 8372a268..4a5dffc2 100644 --- a/src/static/client3.js +++ b/src/static/client3.js @@ -576,6 +576,7 @@ const hashLinkInfo = clientInfo.hashLinkInfo = { }, event: { + beforeHashLinkScrolls: [], whenHashLinkClicked: [], }, }; @@ -638,6 +639,21 @@ function addHashLinkListeners() { return; } + // Don't do anything if the target element isn't actually visible! + if (target.offsetParent === null) { + return; + } + + // Allow event handlers to prevent scrolling. + for (const handler of event.beforeHashLinkScrolls) { + if (handler({ + link: hashLink, + target, + }) === false) { + return; + } + } + // Hide skipper box right away, so the layout is updated on time for the // math operations coming up next. const skipper = document.getElementById('skippers'); @@ -675,6 +691,7 @@ function addHashLinkListeners() { for (const handler of event.whenHashLinkClicked) { handler({ link: hashLink, + target, }); } }); |