2021-10-20 18:58:49 +00:00
|
|
|
// Enable Vector features limited to ES6 browse
|
2021-10-26 23:37:56 +00:00
|
|
|
const
|
2022-12-07 22:10:09 +00:00
|
|
|
limitedWidthToggle = require( './limitedWidthToggle.js' ),
|
2021-10-26 23:37:56 +00:00
|
|
|
searchToggle = require( './searchToggle.js' ),
|
|
|
|
stickyHeader = require( './stickyHeader.js' ),
|
|
|
|
scrollObserver = require( './scrollObserver.js' ),
|
2022-03-17 23:01:17 +00:00
|
|
|
initExperiment = require( './AB.js' ),
|
2022-01-21 20:15:34 +00:00
|
|
|
initSectionObserver = require( './sectionObserver.js' ),
|
|
|
|
initTableOfContents = require( './tableOfContents.js' ),
|
2022-11-28 21:08:40 +00:00
|
|
|
pinnableElement = require( './pinnableElement.js' ),
|
2022-02-08 21:14:33 +00:00
|
|
|
deferUntilFrame = require( './deferUntilFrame.js' ),
|
2022-03-17 23:02:39 +00:00
|
|
|
ABTestConfig = require( /** @type {string} */ ( './config.json' ) ).wgVectorWebABTestEnrollment || {},
|
2022-07-01 20:19:57 +00:00
|
|
|
STICKY_HEADER_VISIBLE_CLASS = 'vector-sticky-header-visible',
|
2022-12-20 22:58:44 +00:00
|
|
|
TOC_ID = 'vector-toc',
|
2022-01-21 20:15:34 +00:00
|
|
|
BODY_CONTENT_ID = 'bodyContent',
|
|
|
|
HEADLINE_SELECTOR = '.mw-headline',
|
2022-03-17 23:01:17 +00:00
|
|
|
TOC_SECTION_ID_PREFIX = 'toc-',
|
2022-03-24 20:49:22 +00:00
|
|
|
PAGE_TITLE_SCROLL_HOOK = 'page_title',
|
2022-12-09 21:27:12 +00:00
|
|
|
PAGE_TITLE_INTERSECTION_CLASS = 'vector-below-page-title';
|
2021-10-20 18:58:49 +00:00
|
|
|
|
2022-07-01 20:19:57 +00:00
|
|
|
const belowDesktopMedia = window.matchMedia( '(max-width: 999px)' );
|
|
|
|
|
2022-03-17 16:54:26 +00:00
|
|
|
/**
|
|
|
|
* @callback OnIntersection
|
|
|
|
* @param {HTMLElement} element The section that triggered the new intersection change.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ignore
|
|
|
|
* @param {Function} changeActiveSection
|
|
|
|
* @return {OnIntersection}
|
|
|
|
*/
|
|
|
|
const getHeadingIntersectionHandler = ( changeActiveSection ) => {
|
|
|
|
/**
|
|
|
|
* @param {HTMLElement} section
|
|
|
|
*/
|
|
|
|
return ( section ) => {
|
|
|
|
const headline = section.classList.contains( 'mw-body-content' ) ?
|
|
|
|
section :
|
|
|
|
section.querySelector( HEADLINE_SELECTOR );
|
|
|
|
if ( headline ) {
|
|
|
|
changeActiveSection( `${TOC_SECTION_ID_PREFIX}${headline.id}` );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-04-14 03:58:05 +00:00
|
|
|
/**
|
|
|
|
* Initialize sticky header AB tests and determine whether to show the sticky header
|
|
|
|
* based on which buckets the user is in.
|
|
|
|
*
|
|
|
|
* @typedef {Object} InitStickyHeaderABTests
|
|
|
|
* @property {boolean} disableEditIcons - Should the sticky header have an edit icon
|
|
|
|
* @property {boolean} showStickyHeader - Should the sticky header be shown
|
|
|
|
* @param {ABTestConfig} abConfig
|
|
|
|
* @param {boolean} isStickyHeaderFeatureAllowed and the user is logged in
|
|
|
|
* @param {function(ABTestConfig): initExperiment.WebABTest} getEnabledExperiment
|
|
|
|
* @return {InitStickyHeaderABTests}
|
|
|
|
*/
|
|
|
|
function initStickyHeaderABTests( abConfig, isStickyHeaderFeatureAllowed, getEnabledExperiment ) {
|
2023-01-19 20:39:55 +00:00
|
|
|
let showStickyHeader = isStickyHeaderFeatureAllowed,
|
2022-04-14 03:58:05 +00:00
|
|
|
stickyHeaderExperiment,
|
2023-01-19 20:39:55 +00:00
|
|
|
disableEditIcons = true;
|
2022-04-14 03:58:05 +00:00
|
|
|
|
2022-06-15 22:01:02 +00:00
|
|
|
// One of the sticky header AB tests is specified in the config
|
|
|
|
const abTestName = abConfig.name,
|
|
|
|
isStickyHeaderExperiment = abTestName === stickyHeader.STICKY_HEADER_EXPERIMENT_NAME ||
|
|
|
|
abTestName === stickyHeader.STICKY_HEADER_EDIT_EXPERIMENT_NAME;
|
|
|
|
|
2022-04-14 03:58:05 +00:00
|
|
|
// Determine if user is eligible for sticky header AB test
|
|
|
|
if (
|
|
|
|
isStickyHeaderFeatureAllowed && // The sticky header can be shown on the page
|
|
|
|
abConfig.enabled && // An AB test config is enabled
|
2022-06-15 22:01:02 +00:00
|
|
|
isStickyHeaderExperiment // The AB test is one of the sticky header experiments
|
2022-04-14 03:58:05 +00:00
|
|
|
) {
|
|
|
|
// If eligible, initialize the AB test
|
|
|
|
stickyHeaderExperiment = getEnabledExperiment( abConfig );
|
2023-01-19 20:39:55 +00:00
|
|
|
disableEditIcons = true;
|
2022-04-14 03:58:05 +00:00
|
|
|
|
Sticky header AB test bucketing for 2 treatment buckets
For idwiki/viwiki, we wish to run the sticky header edit button AB
test so that treatment1 group sees the sticky header without edit
buttons, treatment2 groups sees the sticky header with edit buttons,
and the control/unsampled groups see no sticky header at all.
This patch overrides the configuration to make the sticky header
w/o edit buttons for treatment1, sticky header w/ edit buttons for
treatment2, and hides sticky header for everyone else. This depends
on a configuration with the treatment groups having "treatment1"
and "treatment2" as substrings in their bucket names.
The full configuration for idwiki/viwiki would be something like
the following:
```
$wgVectorStickyHeader = [
"logged_in" => true,
"logged_out" => false,
];
$wgVectorStickyHeaderEdit = [
"logged_in" => true,
"logged_out" => false,
];
$wgVectorWebABTestEnrollment = [
"name" => "vector.sticky_header_edit",
"enabled" => true,
"buckets" => [
"unsampled" => [
"samplingRate" => 0
],
"noStickyHeaderControl" => [
"samplingRate" => 0.34
],
"stickyHeaderNoEditButtonTreatment1" => [
"samplingRate" => 0.33
],
"stickyHeaderEditButtonTreatment2" => [
"samplingRate" => 0.33
]
],
];
```
Bug: T312573
Change-Id: I15c360fdf5393f5594602acc33b5b916e904016d
2022-07-07 19:06:14 +00:00
|
|
|
// If running initial or edit AB test, show sticky header to treatment groups
|
|
|
|
// only. Unsampled and control buckets do not see sticky header.
|
|
|
|
if ( abTestName === stickyHeader.STICKY_HEADER_EXPERIMENT_NAME ||
|
|
|
|
abTestName === stickyHeader.STICKY_HEADER_EDIT_EXPERIMENT_NAME
|
|
|
|
) {
|
2023-01-19 20:39:55 +00:00
|
|
|
showStickyHeader = stickyHeaderExperiment.isInTreatmentBucket();
|
2022-04-14 03:58:05 +00:00
|
|
|
}
|
|
|
|
|
Sticky header AB test bucketing for 2 treatment buckets
For idwiki/viwiki, we wish to run the sticky header edit button AB
test so that treatment1 group sees the sticky header without edit
buttons, treatment2 groups sees the sticky header with edit buttons,
and the control/unsampled groups see no sticky header at all.
This patch overrides the configuration to make the sticky header
w/o edit buttons for treatment1, sticky header w/ edit buttons for
treatment2, and hides sticky header for everyone else. This depends
on a configuration with the treatment groups having "treatment1"
and "treatment2" as substrings in their bucket names.
The full configuration for idwiki/viwiki would be something like
the following:
```
$wgVectorStickyHeader = [
"logged_in" => true,
"logged_out" => false,
];
$wgVectorStickyHeaderEdit = [
"logged_in" => true,
"logged_out" => false,
];
$wgVectorWebABTestEnrollment = [
"name" => "vector.sticky_header_edit",
"enabled" => true,
"buckets" => [
"unsampled" => [
"samplingRate" => 0
],
"noStickyHeaderControl" => [
"samplingRate" => 0.34
],
"stickyHeaderNoEditButtonTreatment1" => [
"samplingRate" => 0.33
],
"stickyHeaderEditButtonTreatment2" => [
"samplingRate" => 0.33
]
],
];
```
Bug: T312573
Change-Id: I15c360fdf5393f5594602acc33b5b916e904016d
2022-07-07 19:06:14 +00:00
|
|
|
// If running edit-button AB test, the edit buttons in sticky header are shown
|
|
|
|
// to second treatment group only.
|
2022-06-15 22:01:02 +00:00
|
|
|
if ( abTestName === stickyHeader.STICKY_HEADER_EDIT_EXPERIMENT_NAME ) {
|
Sticky header AB test bucketing for 2 treatment buckets
For idwiki/viwiki, we wish to run the sticky header edit button AB
test so that treatment1 group sees the sticky header without edit
buttons, treatment2 groups sees the sticky header with edit buttons,
and the control/unsampled groups see no sticky header at all.
This patch overrides the configuration to make the sticky header
w/o edit buttons for treatment1, sticky header w/ edit buttons for
treatment2, and hides sticky header for everyone else. This depends
on a configuration with the treatment groups having "treatment1"
and "treatment2" as substrings in their bucket names.
The full configuration for idwiki/viwiki would be something like
the following:
```
$wgVectorStickyHeader = [
"logged_in" => true,
"logged_out" => false,
];
$wgVectorStickyHeaderEdit = [
"logged_in" => true,
"logged_out" => false,
];
$wgVectorWebABTestEnrollment = [
"name" => "vector.sticky_header_edit",
"enabled" => true,
"buckets" => [
"unsampled" => [
"samplingRate" => 0
],
"noStickyHeaderControl" => [
"samplingRate" => 0.34
],
"stickyHeaderNoEditButtonTreatment1" => [
"samplingRate" => 0.33
],
"stickyHeaderEditButtonTreatment2" => [
"samplingRate" => 0.33
]
],
];
```
Bug: T312573
Change-Id: I15c360fdf5393f5594602acc33b5b916e904016d
2022-07-07 19:06:14 +00:00
|
|
|
if ( stickyHeaderExperiment.isInTreatmentBucket( '1' ) ) {
|
2023-01-19 20:39:55 +00:00
|
|
|
disableEditIcons = true;
|
Sticky header AB test bucketing for 2 treatment buckets
For idwiki/viwiki, we wish to run the sticky header edit button AB
test so that treatment1 group sees the sticky header without edit
buttons, treatment2 groups sees the sticky header with edit buttons,
and the control/unsampled groups see no sticky header at all.
This patch overrides the configuration to make the sticky header
w/o edit buttons for treatment1, sticky header w/ edit buttons for
treatment2, and hides sticky header for everyone else. This depends
on a configuration with the treatment groups having "treatment1"
and "treatment2" as substrings in their bucket names.
The full configuration for idwiki/viwiki would be something like
the following:
```
$wgVectorStickyHeader = [
"logged_in" => true,
"logged_out" => false,
];
$wgVectorStickyHeaderEdit = [
"logged_in" => true,
"logged_out" => false,
];
$wgVectorWebABTestEnrollment = [
"name" => "vector.sticky_header_edit",
"enabled" => true,
"buckets" => [
"unsampled" => [
"samplingRate" => 0
],
"noStickyHeaderControl" => [
"samplingRate" => 0.34
],
"stickyHeaderNoEditButtonTreatment1" => [
"samplingRate" => 0.33
],
"stickyHeaderEditButtonTreatment2" => [
"samplingRate" => 0.33
]
],
];
```
Bug: T312573
Change-Id: I15c360fdf5393f5594602acc33b5b916e904016d
2022-07-07 19:06:14 +00:00
|
|
|
}
|
|
|
|
if ( stickyHeaderExperiment.isInTreatmentBucket( '2' ) ) {
|
2023-01-19 20:39:55 +00:00
|
|
|
disableEditIcons = false;
|
2022-04-14 03:58:05 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-19 20:39:55 +00:00
|
|
|
}
|
|
|
|
if ( !abConfig.enabled ) {
|
|
|
|
disableEditIcons = false;
|
2022-04-14 03:58:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2023-01-19 20:39:55 +00:00
|
|
|
showStickyHeader,
|
|
|
|
disableEditIcons
|
2022-04-14 03:58:05 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-07-01 20:19:57 +00:00
|
|
|
/*
|
|
|
|
* Updates TOC's location in the DOM (in sidebar or sticky header)
|
|
|
|
* depending on if the TOC is collapsed and if the sticky header is visible
|
|
|
|
*
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
const updateTocLocation = () => {
|
2022-11-21 20:46:04 +00:00
|
|
|
const TOC_PINNED_CLASS = 'vector-toc-pinned';
|
2022-10-20 21:32:07 +00:00
|
|
|
const isPinned = document.body.classList.contains( TOC_PINNED_CLASS );
|
2022-07-01 20:19:57 +00:00
|
|
|
const isStickyHeaderVisible = document.body.classList.contains( STICKY_HEADER_VISIBLE_CLASS );
|
|
|
|
const isBelowDesktop = belowDesktopMedia.matches;
|
2022-10-20 21:32:07 +00:00
|
|
|
|
2022-11-21 22:16:07 +00:00
|
|
|
const pinnedContainerId = 'vector-toc-pinned-container';
|
2023-01-13 20:56:22 +00:00
|
|
|
const stickyHeaderUnpinnedContainerId = 'vector-sticky-header-toc-unpinned-container';
|
2022-11-21 22:16:07 +00:00
|
|
|
const pageTitlebarUnpinnedContainerId = 'vector-page-titlebar-toc-unpinned-container';
|
|
|
|
|
|
|
|
let newContainerId = '';
|
|
|
|
if ( isPinned ) {
|
2022-11-28 20:38:57 +00:00
|
|
|
if ( isBelowDesktop ) {
|
2022-11-21 22:16:07 +00:00
|
|
|
// Automatically move the ToC into the page titlebar when pinned on smaller resolutions
|
|
|
|
newContainerId = pageTitlebarUnpinnedContainerId;
|
|
|
|
} else {
|
|
|
|
newContainerId = pinnedContainerId;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ( isStickyHeaderVisible && !isBelowDesktop ) {
|
|
|
|
newContainerId = stickyHeaderUnpinnedContainerId;
|
|
|
|
} else {
|
|
|
|
newContainerId = pageTitlebarUnpinnedContainerId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-13 20:56:22 +00:00
|
|
|
pinnableElement.movePinnableElement( TOC_ID, newContainerId );
|
2022-07-01 20:19:57 +00:00
|
|
|
};
|
|
|
|
|
2021-10-20 18:58:49 +00:00
|
|
|
/**
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
const main = () => {
|
2022-12-07 22:10:09 +00:00
|
|
|
limitedWidthToggle();
|
2021-10-20 18:58:49 +00:00
|
|
|
// Initialize the search toggle for the main header only. The sticky header
|
2022-02-01 20:52:16 +00:00
|
|
|
// toggle is initialized after Codex search loads.
|
2021-10-20 19:10:42 +00:00
|
|
|
const searchToggleElement = document.querySelector( '.mw-header .search-toggle' );
|
|
|
|
if ( searchToggleElement ) {
|
|
|
|
searchToggle( searchToggleElement );
|
|
|
|
}
|
2021-10-26 23:37:56 +00:00
|
|
|
|
2022-12-09 21:27:12 +00:00
|
|
|
//
|
|
|
|
// Pinnable elements
|
|
|
|
//
|
2022-11-28 21:08:40 +00:00
|
|
|
pinnableElement.initPinnableElement();
|
2022-10-19 20:43:40 +00:00
|
|
|
|
2022-07-01 20:19:57 +00:00
|
|
|
//
|
2022-03-23 20:35:27 +00:00
|
|
|
// Sticky header
|
2022-07-01 20:19:57 +00:00
|
|
|
//
|
2022-03-23 20:35:27 +00:00
|
|
|
const
|
|
|
|
header = document.getElementById( stickyHeader.STICKY_HEADER_ID ),
|
|
|
|
stickyIntersection = document.getElementById( stickyHeader.FIRST_HEADING_ID ),
|
|
|
|
userMenu = document.getElementById( stickyHeader.USER_MENU_ID ),
|
|
|
|
allowedNamespace = stickyHeader.isAllowedNamespace( mw.config.get( 'wgNamespaceNumber' ) ),
|
|
|
|
allowedAction = stickyHeader.isAllowedAction( mw.config.get( 'wgAction' ) );
|
|
|
|
|
|
|
|
const isStickyHeaderAllowed =
|
|
|
|
!!header &&
|
|
|
|
!!stickyIntersection &&
|
|
|
|
!!userMenu &&
|
|
|
|
allowedNamespace &&
|
|
|
|
allowedAction &&
|
|
|
|
'IntersectionObserver' in window;
|
|
|
|
|
2022-04-14 03:58:05 +00:00
|
|
|
const { showStickyHeader, disableEditIcons } = initStickyHeaderABTests(
|
|
|
|
ABTestConfig,
|
|
|
|
isStickyHeaderAllowed && !mw.user.isAnon(),
|
|
|
|
( config ) => initExperiment(
|
|
|
|
Object.assign( {}, config, { token: mw.user.getId() } )
|
|
|
|
)
|
|
|
|
);
|
2022-05-27 16:36:17 +00:00
|
|
|
|
2022-07-01 20:19:57 +00:00
|
|
|
// Set up intersection observer for page title
|
|
|
|
// Used to show/hide sticky header and add class used by collapsible TOC (T307900)
|
2021-10-26 23:37:56 +00:00
|
|
|
const observer = scrollObserver.initScrollObserver(
|
|
|
|
() => {
|
2022-04-14 03:58:05 +00:00
|
|
|
if ( isStickyHeaderAllowed && showStickyHeader ) {
|
2022-05-05 20:54:20 +00:00
|
|
|
stickyHeader.show();
|
2022-07-01 20:19:57 +00:00
|
|
|
updateTocLocation();
|
2021-12-01 22:31:48 +00:00
|
|
|
}
|
2022-07-01 20:19:57 +00:00
|
|
|
document.body.classList.add( PAGE_TITLE_INTERSECTION_CLASS );
|
2022-03-24 20:49:22 +00:00
|
|
|
scrollObserver.fireScrollHook( 'down', PAGE_TITLE_SCROLL_HOOK );
|
2021-10-26 23:37:56 +00:00
|
|
|
},
|
|
|
|
() => {
|
2022-04-14 03:58:05 +00:00
|
|
|
if ( isStickyHeaderAllowed && showStickyHeader ) {
|
2022-05-05 20:54:20 +00:00
|
|
|
stickyHeader.hide();
|
2022-07-01 20:19:57 +00:00
|
|
|
updateTocLocation();
|
2021-12-01 22:31:48 +00:00
|
|
|
}
|
2022-07-01 20:19:57 +00:00
|
|
|
document.body.classList.remove( PAGE_TITLE_INTERSECTION_CLASS );
|
2022-03-24 20:49:22 +00:00
|
|
|
scrollObserver.fireScrollHook( 'up', PAGE_TITLE_SCROLL_HOOK );
|
2021-10-26 23:37:56 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2022-07-01 20:19:57 +00:00
|
|
|
// Handle toc location when sticky header is hidden on lower viewports
|
|
|
|
belowDesktopMedia.onchange = () => {
|
|
|
|
updateTocLocation();
|
|
|
|
};
|
|
|
|
|
2022-12-09 21:27:12 +00:00
|
|
|
updateTocLocation();
|
|
|
|
|
2022-05-31 22:33:31 +00:00
|
|
|
if ( !showStickyHeader ) {
|
|
|
|
stickyHeader.hide();
|
|
|
|
}
|
|
|
|
|
2022-04-14 03:58:05 +00:00
|
|
|
if ( isStickyHeaderAllowed && showStickyHeader ) {
|
2022-03-23 20:35:27 +00:00
|
|
|
stickyHeader.initStickyHeader( {
|
|
|
|
header,
|
|
|
|
userMenu,
|
|
|
|
observer,
|
2022-04-14 03:58:05 +00:00
|
|
|
stickyIntersection,
|
|
|
|
disableEditIcons
|
2022-03-23 20:35:27 +00:00
|
|
|
} );
|
|
|
|
} else if ( stickyIntersection ) {
|
|
|
|
observer.observe( stickyIntersection );
|
2021-12-01 22:31:48 +00:00
|
|
|
}
|
2022-01-21 20:15:34 +00:00
|
|
|
|
2022-12-09 21:27:12 +00:00
|
|
|
//
|
|
|
|
// Table of contents
|
|
|
|
//
|
2023-01-13 20:56:22 +00:00
|
|
|
const tocElement = document.getElementById( TOC_ID );
|
2022-06-10 17:58:21 +00:00
|
|
|
const bodyContent = document.getElementById( BODY_CONTENT_ID );
|
|
|
|
|
2022-01-21 20:15:34 +00:00
|
|
|
if ( !(
|
|
|
|
tocElement &&
|
|
|
|
bodyContent &&
|
|
|
|
window.IntersectionObserver &&
|
2022-03-17 23:02:39 +00:00
|
|
|
window.requestAnimationFrame
|
|
|
|
) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-21 20:15:34 +00:00
|
|
|
const tableOfContents = initTableOfContents( {
|
|
|
|
container: tocElement,
|
2022-02-15 22:43:04 +00:00
|
|
|
onHeadingClick: ( id ) => {
|
2022-02-07 19:20:17 +00:00
|
|
|
|
2022-02-11 18:14:25 +00:00
|
|
|
// eslint-disable-next-line no-use-before-define
|
2022-01-21 20:15:34 +00:00
|
|
|
sectionObserver.pause();
|
|
|
|
|
2022-02-07 19:20:17 +00:00
|
|
|
tableOfContents.expandSection( id );
|
|
|
|
tableOfContents.changeActiveSection( id );
|
|
|
|
|
2022-02-08 21:14:33 +00:00
|
|
|
// T297614: We want the link that the user has clicked inside the TOC to
|
|
|
|
// be "active" (e.g. bolded) regardless of whether the browser's scroll
|
|
|
|
// position corresponds to that section. Therefore, we need to temporarily
|
|
|
|
// ignore section observer until the browser has finished scrolling to the
|
|
|
|
// section (if needed).
|
|
|
|
//
|
|
|
|
// However, because the scroll event happens asyncronously after the user
|
|
|
|
// clicks on a link and may not even happen at all (e.g. the user has
|
|
|
|
// scrolled all the way to the bottom and clicks a section that is already
|
|
|
|
// in the viewport), determining when we should resume section observer is
|
|
|
|
// a bit tricky.
|
|
|
|
//
|
|
|
|
// Because a scroll event may not even be triggered after clicking the
|
|
|
|
// link, we instead allow the browser to perform a maximum number of
|
|
|
|
// repaints before resuming sectionObserver. Per T297614#7687656, Firefox
|
|
|
|
// 97.0 wasn't consistently activating the table of contents section that
|
|
|
|
// the user clicked even after waiting 2 frames. After further
|
|
|
|
// investigation, it sometimes waits up to 3 frames before painting the
|
|
|
|
// new scroll position so we have that as the limit.
|
2022-02-11 18:14:25 +00:00
|
|
|
//
|
|
|
|
// eslint-disable-next-line no-use-before-define
|
2022-02-08 21:14:33 +00:00
|
|
|
deferUntilFrame( () => sectionObserver.resume(), 3 );
|
2022-02-15 22:43:04 +00:00
|
|
|
},
|
|
|
|
onToggleClick: ( id ) => {
|
|
|
|
tableOfContents.toggleExpandSection( id );
|
2022-07-01 20:19:57 +00:00
|
|
|
},
|
2022-10-20 21:32:07 +00:00
|
|
|
onTogglePinned: updateTocLocation
|
2022-01-21 20:15:34 +00:00
|
|
|
} );
|
2022-03-31 16:30:36 +00:00
|
|
|
const headingSelector = [
|
|
|
|
'h1', 'h2', 'h3', 'h4', 'h5', 'h6'
|
2022-12-13 22:11:32 +00:00
|
|
|
].map( ( tag ) => `.mw-parser-output ${tag}` ).join( ',' );
|
2022-02-11 18:14:25 +00:00
|
|
|
const sectionObserver = initSectionObserver( {
|
2022-03-31 16:30:36 +00:00
|
|
|
elements: bodyContent.querySelectorAll( `${headingSelector}, .mw-body-content` ),
|
2022-03-23 20:35:27 +00:00
|
|
|
topMargin: header ? header.getBoundingClientRect().height : 0,
|
2022-03-17 16:54:26 +00:00
|
|
|
onIntersection: getHeadingIntersectionHandler( tableOfContents.changeActiveSection )
|
2022-01-21 20:15:34 +00:00
|
|
|
} );
|
2021-10-20 19:10:42 +00:00
|
|
|
};
|
2021-10-20 18:58:49 +00:00
|
|
|
|
2021-10-30 01:01:36 +00:00
|
|
|
module.exports = {
|
2022-03-17 16:54:26 +00:00
|
|
|
main,
|
|
|
|
test: {
|
2022-04-14 03:58:05 +00:00
|
|
|
initStickyHeaderABTests,
|
2022-03-17 16:54:26 +00:00
|
|
|
getHeadingIntersectionHandler
|
|
|
|
}
|
2021-10-30 01:01:36 +00:00
|
|
|
};
|