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-09-10 22:28:12 +00:00
|
|
|
overflowElements = require( './overflowElements.js' );
|
2023-07-12 01:44:34 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
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-11-02 06:00:21 +00:00
|
|
|
setupObservers = require( './setupObservers.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
|
|
|
|
2024-11-03 15:39:10 +00:00
|
|
|
dropdown.init();
|
|
|
|
search.init( window );
|
|
|
|
echo();
|
2024-07-03 21:44:52 +00:00
|
|
|
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' );
|
|
|
|
}
|
|
|
|
|
2024-11-03 15:39:10 +00:00
|
|
|
// Defer non-essential tasks
|
|
|
|
setTimeout( () => {
|
2024-11-06 23:51:08 +00:00
|
|
|
setupObservers.main();
|
2024-11-03 15:39:10 +00:00
|
|
|
registerServiceWorker();
|
2022-10-23 20:37:43 +00:00
|
|
|
|
2024-11-03 15:39:10 +00:00
|
|
|
window.addEventListener( 'beforeunload', () => {
|
|
|
|
// Set up loading indicator
|
|
|
|
document.documentElement.classList.add( 'citizen-loading' );
|
|
|
|
}, false );
|
2023-10-26 21:41:14 +00:00
|
|
|
|
2024-11-03 15:39:10 +00:00
|
|
|
// Remove loading indicator once the page is unloaded/hidden
|
|
|
|
window.addEventListener( 'pagehide', () => {
|
|
|
|
document.documentElement.classList.remove( 'citizen-loading' );
|
|
|
|
} );
|
|
|
|
}, 0 );
|
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 );
|
|
|
|
} );
|
|
|
|
}
|