Update scroll observer to allow event logging
- Permits logging for scroll events without sticky header. - Update function name to be more precise. Bug: T292586 Change-Id: I441b4bf81bc4a36a03f0f1c215d86b01dce2911d
This commit is contained in:
parent
ca251c25f8
commit
37c9a24f75
|
@ -26,15 +26,9 @@ const main = () => {
|
|||
// Note that the default test group is set to experience the feature by default.
|
||||
// @ts-ignore
|
||||
testGroup = stickyConfig ? stickyConfig.group : scrollObserver.FEATURE_TEST_GROUP,
|
||||
targetElement = stickyHeader.header;
|
||||
|
||||
// Check for target html, sticky header conditionals, and test group to continue.
|
||||
if ( !( targetElement &&
|
||||
stickyHeader.isStickyHeaderAllowed() &&
|
||||
testGroup !== 'unsampled' )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
targetElement = stickyHeader.header,
|
||||
targetIntersection = stickyHeader.stickyIntersection,
|
||||
isStickyHeaderAllowed = stickyHeader.isStickyHeaderAllowed() && testGroup !== 'unsampled';
|
||||
|
||||
// Fire the A/B test enrollment hook.
|
||||
AB.initAB( testGroup );
|
||||
|
@ -43,17 +37,25 @@ const main = () => {
|
|||
// for event logging if AB test is enabled.
|
||||
const observer = scrollObserver.initScrollObserver(
|
||||
() => {
|
||||
scrollObserver.onShowFeature( targetElement, testGroup );
|
||||
scrollObserver.logScrollEvent( 'down' );
|
||||
if ( targetElement && isStickyHeaderAllowed ) {
|
||||
scrollObserver.onShowFeature( targetElement, testGroup );
|
||||
}
|
||||
scrollObserver.fireScrollHook( 'down' );
|
||||
},
|
||||
() => {
|
||||
scrollObserver.onHideFeature( targetElement, testGroup );
|
||||
scrollObserver.logScrollEvent( 'up' );
|
||||
if ( targetElement && isStickyHeaderAllowed ) {
|
||||
scrollObserver.onHideFeature( targetElement, testGroup );
|
||||
}
|
||||
scrollObserver.fireScrollHook( 'up' );
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
stickyHeader.initStickyHeader( observer );
|
||||
if ( isStickyHeaderAllowed ) {
|
||||
stickyHeader.initStickyHeader( observer );
|
||||
} else if ( targetIntersection ) {
|
||||
observer.observe( targetIntersection );
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
|
|
@ -48,7 +48,7 @@ function onHideFeature( element, group ) {
|
|||
*
|
||||
* @param {string} direction the scroll direction
|
||||
*/
|
||||
function logScrollEvent( direction ) {
|
||||
function fireScrollHook( direction ) {
|
||||
if ( direction === 'down' ) {
|
||||
// @ts-ignore
|
||||
mw.hook( SCROLL_HOOK ).fire( { context: SCROLL_CONTEXT_BELOW } );
|
||||
|
@ -85,6 +85,6 @@ module.exports = {
|
|||
initScrollObserver,
|
||||
onShowFeature,
|
||||
onHideFeature,
|
||||
logScrollEvent,
|
||||
fireScrollHook,
|
||||
FEATURE_TEST_GROUP
|
||||
};
|
||||
|
|
|
@ -427,5 +427,6 @@ module.exports = {
|
|||
initStickyHeader,
|
||||
isStickyHeaderAllowed,
|
||||
header,
|
||||
stickyIntersection,
|
||||
STICKY_HEADER_EXPERIMENT_NAME
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue