Merge "Initialize the skins.vector.es6 module before the skins.vector.js module"

This commit is contained in:
jenkins-bot 2021-11-04 18:11:29 +00:00 committed by Gerrit Code Review
commit 04ff34bd0c
2 changed files with 31 additions and 11 deletions

View File

@ -15,9 +15,6 @@ const main = () => {
stickyHeader();
};
if ( document.readyState === 'interactive' || document.readyState === 'complete' ) {
main();
} else {
// This is needed when document.readyState === 'loading'.
document.addEventListener( 'DOMContentLoaded', () => main );
}
module.exports = {
main: main
};

View File

@ -81,11 +81,34 @@ function init( window ) {
init( window );
if ( document.readyState === 'interactive' || document.readyState === 'complete' ) {
main( window );
} else {
// This is needed when document.readyState === 'loading'.
document.addEventListener( 'DOMContentLoaded', function () {
/**
* Because stickyHeader.js clones the user menu, it must initialize before
* dropdownMenus.js initializes in order for the sticky header's user menu to
* bind the necessary checkboxHack event listeners. This is solved by using
* mw.loader.using to ensure that the skins.vector.es6 module initializes first
* followed by initializing this module. If the es6 module loading fails (which
* can happen in browsers that don't support es6), continue to initialize this
* module.
*/
function initAfterEs6Module() {
mw.loader.using( 'skins.vector.es6' ).then( function () {
// Loading of the 'skins.vector.es6' module has succeeded. Initialize the
// `skins.vector.es6` module first.
require( /** @type {string} */ ( 'skins.vector.es6' ) ).main();
// Initialize this module second.
main( window );
}, function () {
// Loading of the 'skins.vector.es6' has failed (e.g. this will fail in
// browsers that don't support ES6) so only initialize this module.
main( window );
} );
}
if ( document.readyState === 'interactive' || document.readyState === 'complete' ) {
initAfterEs6Module();
} else {
// This is needed when document.readyState === 'loading'.
document.addEventListener( 'DOMContentLoaded', function () {
initAfterEs6Module();
} );
}