2022-05-13 02:37:28 +00:00
|
|
|
const
|
|
|
|
checkboxHack = require( './checkboxHack.js' ),
|
|
|
|
CHECKBOX_HACK_CONTAINER_SELECTOR = '.mw-checkbox-hack-container',
|
|
|
|
CHECKBOX_HACK_CHECKBOX_SELECTOR = '.mw-checkbox-hack-checkbox',
|
|
|
|
CHECKBOX_HACK_BUTTON_SELECTOR = '.mw-checkbox-hack-button',
|
|
|
|
CHECKBOX_HACK_TARGET_SELECTOR = '.mw-checkbox-hack-target';
|
|
|
|
|
2021-01-16 22:01:58 +00:00
|
|
|
/**
|
2022-05-13 02:37:28 +00:00
|
|
|
* Wait for first paint before calling this function.
|
2021-03-13 17:43:28 +00:00
|
|
|
* (see T234570#5779890, T246419).
|
|
|
|
*
|
|
|
|
* @param {Document} document
|
2021-01-16 22:01:58 +00:00
|
|
|
* @return {void}
|
|
|
|
*/
|
2021-03-13 17:43:28 +00:00
|
|
|
function enableCssAnimations( document ) {
|
|
|
|
document.documentElement.classList.add( 'citizen-animations-ready' );
|
|
|
|
}
|
|
|
|
|
2021-04-21 20:45:52 +00:00
|
|
|
/**
|
2022-05-13 02:37:28 +00:00
|
|
|
* Add the ability for users to toggle dropdown menus using the enter key (as
|
|
|
|
* well as space) using core's checkboxHack.
|
2021-04-21 20:45:52 +00:00
|
|
|
*
|
2022-05-13 02:37:28 +00:00
|
|
|
* Based on Vector
|
2021-04-21 20:45:52 +00:00
|
|
|
*/
|
2022-05-13 02:37:28 +00:00
|
|
|
function bind() {
|
|
|
|
// Search for all dropdown containers using the CHECKBOX_HACK_CONTAINER_SELECTOR.
|
|
|
|
const containers = document.querySelectorAll( CHECKBOX_HACK_CONTAINER_SELECTOR );
|
|
|
|
|
|
|
|
containers.forEach( ( container ) => {
|
|
|
|
const
|
|
|
|
checkbox = container.querySelector( CHECKBOX_HACK_CHECKBOX_SELECTOR ),
|
|
|
|
button = container.querySelector( CHECKBOX_HACK_BUTTON_SELECTOR ),
|
|
|
|
target = container.querySelector( CHECKBOX_HACK_TARGET_SELECTOR );
|
2021-04-21 20:45:52 +00:00
|
|
|
|
2022-05-13 02:37:28 +00:00
|
|
|
if ( !( checkbox && button && target ) ) {
|
|
|
|
return;
|
2021-04-21 20:45:52 +00:00
|
|
|
}
|
2022-05-13 02:37:28 +00:00
|
|
|
|
|
|
|
checkboxHack.bind( window, checkbox, button, target );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* T295085: Close all dropdown menus when page is unloaded to prevent them from
|
|
|
|
* being open when navigating back to a page.
|
|
|
|
*
|
|
|
|
* Based on Vector
|
|
|
|
*/
|
|
|
|
function bindCloseOnUnload() {
|
2022-05-13 02:44:17 +00:00
|
|
|
addEventListener( 'beforeunload', () => {
|
2022-05-13 02:37:28 +00:00
|
|
|
const checkboxes = document.querySelectorAll( CHECKBOX_HACK_CHECKBOX_SELECTOR + ':checked' );
|
|
|
|
|
|
|
|
checkboxes.forEach( ( checkbox ) => {
|
|
|
|
/** @type {HTMLInputElement} */ ( checkbox ).checked = false;
|
|
|
|
} );
|
2021-04-21 20:45:52 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2021-04-26 15:39:27 +00:00
|
|
|
/**
|
|
|
|
* Add a class to indicate that page title is outside of viewport
|
|
|
|
*
|
|
|
|
* @param {Document} document
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
function onTitleHidden( document ) {
|
|
|
|
const title = document.getElementById( 'firstHeading' );
|
|
|
|
|
|
|
|
if ( title ) {
|
2022-05-13 04:21:08 +00:00
|
|
|
const scrollObserver = require( './scrollObserver.js' );
|
|
|
|
|
|
|
|
const observer = scrollObserver.initScrollObserver(
|
|
|
|
() => {
|
2022-05-13 04:30:46 +00:00
|
|
|
document.body.classList.add( 'citizen-title--hidden' );
|
2022-05-13 04:21:08 +00:00
|
|
|
},
|
|
|
|
() => {
|
2022-05-13 04:30:46 +00:00
|
|
|
document.body.classList.remove( 'citizen-title--hidden' );
|
2021-04-26 15:39:27 +00:00
|
|
|
}
|
2022-05-13 04:21:08 +00:00
|
|
|
);
|
2021-04-26 15:39:27 +00:00
|
|
|
observer.observe( title );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-13 17:43:28 +00:00
|
|
|
/**
|
2021-03-13 17:45:03 +00:00
|
|
|
* @param {Window} window
|
2021-03-13 17:43:28 +00:00
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
function main( window ) {
|
2022-05-20 21:33:10 +00:00
|
|
|
const search = require( './search.js' );
|
2022-05-13 04:21:08 +00:00
|
|
|
|
|
|
|
const tocContainer = document.getElementById( 'toc' );
|
2021-04-21 17:44:28 +00:00
|
|
|
|
2021-03-13 17:43:28 +00:00
|
|
|
enableCssAnimations( window.document );
|
2021-04-21 22:47:03 +00:00
|
|
|
search.init( window );
|
2021-04-26 15:39:27 +00:00
|
|
|
onTitleHidden( window.document );
|
2021-04-27 16:57:54 +00:00
|
|
|
|
2021-06-12 13:54:47 +00:00
|
|
|
window.addEventListener( 'beforeunload', () => {
|
|
|
|
document.documentElement.classList.add( 'citizen-loading' );
|
|
|
|
}, false );
|
|
|
|
|
2022-05-13 02:37:28 +00:00
|
|
|
bind();
|
|
|
|
bindCloseOnUnload();
|
|
|
|
|
|
|
|
// Handle ToC
|
|
|
|
// TODO: There must be a cleaner way to do this
|
|
|
|
if ( tocContainer ) {
|
|
|
|
const toc = require( './tableOfContents.js' );
|
2022-05-17 19:10:14 +00:00
|
|
|
toc.init();
|
2022-05-13 02:37:28 +00:00
|
|
|
|
|
|
|
checkboxHack.bind(
|
|
|
|
window,
|
|
|
|
document.getElementById( 'toctogglecheckbox' ),
|
|
|
|
tocContainer.querySelector( '.toctogglelabel' ),
|
|
|
|
tocContainer.querySelector( 'ul' )
|
|
|
|
);
|
2022-05-12 21:18:39 +00:00
|
|
|
}
|
|
|
|
|
2021-04-27 16:57:54 +00:00
|
|
|
mw.loader.load( 'skins.citizen.preferences' );
|
2021-01-16 22:01:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-04 21:42:06 +00:00
|
|
|
if ( document.readyState === 'interactive' || document.readyState === 'complete' ) {
|
|
|
|
main( window );
|
|
|
|
} else {
|
|
|
|
document.addEventListener( 'DOMContentLoaded', function () {
|
|
|
|
main( window );
|
|
|
|
} );
|
|
|
|
}
|