feat: client-side hooks for navigator scroll action

isekai-main
Julian Lam 2 years ago
parent 664bc5f54d
commit 135fe55bed

@ -561,12 +561,14 @@ define('navigator', ['forum/pagination', 'components', 'hooks', 'alerts'], funct
navigator.scrollToElement(scrollTo, highlight, duration, topicIndex); navigator.scrollToElement(scrollTo, highlight, duration, topicIndex);
}; };
navigator.scrollToElement = function (scrollTo, highlight, duration, newIndex = null) { navigator.scrollToElement = async (scrollTo, highlight, duration, newIndex = null) => {
if (!scrollTo.length) { if (!scrollTo.length) {
navigator.scrollActive = false; navigator.scrollActive = false;
return; return;
} }
await hooks.fire('filter:navigator.scroll', { scrollTo, highlight, duration, newIndex });
const postHeight = scrollTo.outerHeight(true); const postHeight = scrollTo.outerHeight(true);
const navbarHeight = components.get('navbar').outerHeight(true); const navbarHeight = components.get('navbar').outerHeight(true);
const topicHeaderHeight = $('.topic-header').outerHeight(true) || 0; const topicHeaderHeight = $('.topic-header').outerHeight(true) || 0;
@ -584,6 +586,8 @@ define('navigator', ['forum/pagination', 'components', 'hooks', 'alerts'], funct
// Re-enable onScroll behaviour // Re-enable onScroll behaviour
setTimeout(() => { // fixes race condition from jQuery — onAnimateComplete called too quickly setTimeout(() => { // fixes race condition from jQuery — onAnimateComplete called too quickly
$(window).on('scroll', navigator.delayedUpdate); $(window).on('scroll', navigator.delayedUpdate);
hooks.fire('action:navigator.scrolled', { scrollTo, highlight, duration, newIndex });
}, 50); }, 50);
} }
function onAnimateComplete() { function onAnimateComplete() {

Loading…
Cancel
Save