diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-11-24 15:22:49 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-11-24 15:22:49 -0400 |
commit | 1443cf743ee1f5967022d661b92caba6633de7aa (patch) | |
tree | 125e1db3aba3316fd798edb08dd1b6d47bfe6905 /src/static/client3.js | |
parent | 5931dde25d47695444419e9576dcdcc7d21d4a3f (diff) | |
parent | ce46282c4d6cadb3a90243b7e0aa452e2dfa90d3 (diff) |
Merge branch 'album-commentary-tweaks' into preview
Diffstat (limited to 'src/static/client3.js')
-rw-r--r-- | src/static/client3.js | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/src/static/client3.js b/src/static/client3.js index d0973e46..866b9ba2 100644 --- a/src/static/client3.js +++ b/src/static/client3.js @@ -96,14 +96,18 @@ function dispatchInternalEvent(event, eventName, ...args) { throw new Error(`Event name "${eventName}" isn't stored on ${infoName}.event`); } + let results = []; for (const listener of listeners) { try { - listener(...args); + results.push(listener(...args)); } catch (error) { console.warn(`Uncaught error in listener for ${infoName}.${eventName}`); console.debug(error); + results.push(undefined); } } + + return results; } // JS-based links ----------------------------------------- @@ -1102,13 +1106,14 @@ function addHashLinkListeners() { } // Allow event handlers to prevent scrolling. - for (const handler of event.beforeHashLinkScrolls) { - if (handler({ + const listenerResults = + dispatchInternalEvent(event, 'beforeHashLinkScrolls', { link: hashLink, target, - }) === false) { - return; - } + }); + + if (listenerResults.includes(false)) { + return; } // Hide skipper box right away, so the layout is updated on time for the @@ -1145,14 +1150,10 @@ function addHashLinkListeners() { processScrollingAfterHashLinkClicked(); - dispatchInternalEvent(event, 'whenHashLinkClicked', {link: hashLink}); - - for (const handler of event.whenHashLinkClicked) { - handler({ - link: hashLink, - target, - }); - } + dispatchInternalEvent(event, 'whenHashLinkClicked', { + link: hashLink, + target, + }); }); } @@ -1375,11 +1376,12 @@ function updateStickySubheadingContent(index) { child.remove(); } - for (const child of closestHeading.childNodes) { - if (child.classList?.contains('content-heading-accent')) { - continue; - } + const textContainer = + closestHeading.querySelector('.content-heading-main-title') + // Just for compatibility with older builds of the site. + ?? closestHeading; + for (const child of textContainer.childNodes) { if (child.tagName === 'A') { for (const grandchild of child.childNodes) { stickySubheading.appendChild(grandchild.cloneNode(true)); @@ -1398,12 +1400,10 @@ function updateStickySubheadingContent(index) { state.displayedHeading = closestHeading; - for (const handler of event.whenDisplayedHeadingChanges) { - handler(index, { - oldHeading: oldDisplayedHeading, - newHeading: closestHeading, - }); - } + dispatchInternalEvent(event, 'whenDisplayedHeadingChanges', index, { + oldHeading: oldDisplayedHeading, + newHeading: closestHeading, + }); } function updateStickyHeadings(index) { |