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' );
|
|
|
|
}
|
|
|
|
|
2022-10-23 20:37:43 +00:00
|
|
|
/**
|
|
|
|
* Register service worker
|
|
|
|
*
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
function registerServiceWorker() {
|
|
|
|
const scriptPath = mw.config.get( 'wgScriptPath' );
|
|
|
|
|
|
|
|
// Only allow serviceWorker when the scriptPath is at root because of its scope
|
2022-11-09 22:40:31 +00:00
|
|
|
// I can't figure out how to add the Service-Worker-Allowed HTTP header
|
|
|
|
// to change the default scope
|
2022-10-23 20:37:43 +00:00
|
|
|
if ( scriptPath === '' ) {
|
|
|
|
if ( 'serviceWorker' in navigator ) {
|
|
|
|
const SW_MODULE_NAME = 'skins.citizen.serviceWorker',
|
|
|
|
version = mw.loader.moduleRegistry[ SW_MODULE_NAME ].version,
|
|
|
|
// HACK: Faking a RL link
|
|
|
|
swUrl = scriptPath +
|
|
|
|
'/load.php?modules=' + SW_MODULE_NAME +
|
|
|
|
'&only=scripts&raw=true&skin=citizen&version=' + version;
|
|
|
|
navigator.serviceWorker.register( swUrl, { scope: '/' } );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-12 01:44:34 +00:00
|
|
|
/**
|
|
|
|
* Initialize scripts related to wiki page content
|
|
|
|
*
|
|
|
|
* @param {HTMLElement} bodyContent
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
function initBodyContent( bodyContent ) {
|
|
|
|
const
|
|
|
|
sections = require( './sections.js' ),
|
2024-05-27 19:46:49 +00:00
|
|
|
overflowElements = require( './overflowElements.js' ),
|
2023-07-12 01:44:34 +00:00
|
|
|
toc = require( './tableOfContents.js' );
|
|
|
|
|
|
|
|
// Collapsable sections
|
|
|
|
sections.init( bodyContent );
|
2024-05-27 19:46:49 +00:00
|
|
|
// Overflow element enhancements
|
|
|
|
overflowElements.init( bodyContent );
|
2023-07-12 01:44:34 +00:00
|
|
|
// Table of contents
|
|
|
|
toc.init( bodyContent );
|
|
|
|
}
|
|
|
|
|
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 ) {
|
2023-01-26 00:40:52 +00:00
|
|
|
const
|
2023-03-27 18:08:38 +00:00
|
|
|
config = require( './config.json' ),
|
2024-07-06 00:37:52 +00:00
|
|
|
echo = require( './echo.js' ),
|
2023-01-26 00:40:52 +00:00
|
|
|
search = require( './search.js' ),
|
2024-07-03 21:44:52 +00:00
|
|
|
dropdown = require( './dropdown.js' ),
|
2024-07-01 17:19:31 +00:00
|
|
|
stickyHeader = require( './stickyHeader.js' ),
|
2024-05-08 20:39:47 +00:00
|
|
|
lastModified = require( './lastModified.js' ),
|
2024-07-03 21:44:52 +00:00
|
|
|
share = require( './share.js' );
|
2022-05-13 04:21:08 +00:00
|
|
|
|
2021-03-13 17:43:28 +00:00
|
|
|
enableCssAnimations( window.document );
|
2024-07-06 00:37:52 +00:00
|
|
|
echo();
|
2021-04-21 22:47:03 +00:00
|
|
|
search.init( window );
|
2024-05-30 06:19:53 +00:00
|
|
|
dropdown.init();
|
2024-07-03 21:44:52 +00:00
|
|
|
stickyHeader.init();
|
|
|
|
lastModified.init();
|
|
|
|
share.init();
|
2022-05-13 02:37:28 +00:00
|
|
|
|
2024-06-07 19:01:54 +00:00
|
|
|
mw.hook( 'wikipage.content' ).add( ( content ) => {
|
2023-04-30 21:01:29 +00:00
|
|
|
// content is a jQuery object
|
|
|
|
// note that this refers to .mw-body-content, not #bodyContent
|
2023-07-12 01:44:34 +00:00
|
|
|
initBodyContent( content[ 0 ] );
|
2023-04-30 21:01:29 +00:00
|
|
|
} );
|
|
|
|
|
2023-03-27 18:08:38 +00:00
|
|
|
// Preference module
|
2023-07-03 12:48:41 +00:00
|
|
|
if ( config.wgCitizenEnablePreferences === true && typeof document.createElement( 'div' ).prepend === 'function' ) {
|
2023-03-27 18:08:38 +00:00
|
|
|
mw.loader.load( 'skins.citizen.preferences' );
|
|
|
|
}
|
|
|
|
|
2022-11-09 22:46:55 +00:00
|
|
|
registerServiceWorker();
|
2022-10-23 20:37:43 +00:00
|
|
|
|
|
|
|
window.addEventListener( 'beforeunload', () => {
|
2022-11-09 22:46:55 +00:00
|
|
|
// Set up loading indicator
|
2022-10-23 20:37:43 +00:00
|
|
|
document.documentElement.classList.add( 'citizen-loading' );
|
|
|
|
}, false );
|
2023-10-26 21:41:14 +00:00
|
|
|
|
2024-03-19 22:49:35 +00:00
|
|
|
// Remove loading indicator once the page is unloaded/hidden
|
|
|
|
window.addEventListener( 'pagehide', () => {
|
|
|
|
document.documentElement.classList.remove( 'citizen-loading' );
|
2023-10-26 21:41:14 +00:00
|
|
|
} );
|
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 {
|
2024-06-07 19:01:54 +00:00
|
|
|
document.addEventListener( 'DOMContentLoaded', () => {
|
2022-06-04 21:42:06 +00:00
|
|
|
main( window );
|
|
|
|
} );
|
|
|
|
}
|