feat: client-side hooks for navigator scroll action

This commit is contained in:
Julian Lam
2022-09-19 14:27:35 -04:00
parent 664bc5f54d
commit 135fe55bed

View File

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