2022-04-27 19:32:19 +00:00
|
|
|
var languageButton = require( './languageButton.js' ),
|
2020-08-04 12:02:50 +00:00
|
|
|
initSearchLoader = require( './searchLoader.js' ).initSearchLoader,
|
2022-08-16 19:50:34 +00:00
|
|
|
dropdownMenus = require( './dropdownMenus.js' ).dropdownMenus,
|
2022-06-10 20:45:18 +00:00
|
|
|
sidebarPersistence = require( './sidebarPersistence.js' ),
|
|
|
|
checkbox = require( './checkbox.js' );
|
2020-04-10 15:24:13 +00:00
|
|
|
|
2020-05-28 20:19:06 +00:00
|
|
|
/**
|
|
|
|
* Wait for first paint before calling this function. That's its whole purpose.
|
|
|
|
*
|
|
|
|
* Some CSS animations and transitions are "disabled" by default as a workaround to this old Chrome
|
|
|
|
* bug, https://bugs.chromium.org/p/chromium/issues/detail?id=332189, which otherwise causes them to
|
|
|
|
* render in their terminal state on page load. By adding the `vector-animations-ready` class to the
|
|
|
|
* `html` root element **after** first paint, the animation selectors suddenly match causing the
|
|
|
|
* animations to become "enabled" when they will work properly. A similar pattern is used in Minerva
|
|
|
|
* (see T234570#5779890, T246419).
|
|
|
|
*
|
|
|
|
* Example usage in Less:
|
|
|
|
*
|
|
|
|
* ```less
|
|
|
|
* .foo {
|
|
|
|
* color: #f00;
|
2022-05-13 20:34:51 +00:00
|
|
|
* transform: translateX( -100% );
|
2020-05-28 20:19:06 +00:00
|
|
|
* }
|
|
|
|
*
|
|
|
|
* // This transition will be disabled initially for JavaScript users. It will never be enabled for
|
2022-05-13 19:41:15 +00:00
|
|
|
* // non-JavaScript users.
|
2020-05-28 20:19:06 +00:00
|
|
|
* .vector-animations-ready .foo {
|
2022-05-13 19:41:15 +00:00
|
|
|
* transition: transform 100ms ease-out;
|
2020-05-28 20:19:06 +00:00
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* @param {Document} document
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
function enableCssAnimations( document ) {
|
|
|
|
document.documentElement.classList.add( 'vector-animations-ready' );
|
|
|
|
}
|
|
|
|
|
2020-03-30 20:07:35 +00:00
|
|
|
/**
|
|
|
|
* @param {Window} window
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
function main( window ) {
|
2021-09-03 15:55:50 +00:00
|
|
|
enableCssAnimations( window.document );
|
2022-06-10 20:45:18 +00:00
|
|
|
sidebarPersistence.init();
|
2022-07-26 18:58:01 +00:00
|
|
|
checkbox.init( window.document );
|
2021-09-03 15:55:50 +00:00
|
|
|
initSearchLoader( document );
|
|
|
|
languageButton();
|
2021-10-21 15:59:58 +00:00
|
|
|
dropdownMenus();
|
2021-09-03 15:55:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Window} window
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
function init( window ) {
|
2021-03-17 23:04:42 +00:00
|
|
|
var now = mw.now();
|
|
|
|
// This is the earliest time we can run JS for users (and bucket anonymous
|
|
|
|
// users for A/B tests).
|
|
|
|
// Where the browser supports it, for a 10% sample of users
|
|
|
|
// we record a value to give us a sense of the expected delay in running A/B tests or
|
|
|
|
// disabling JS features. This will inform us on various things including what to expect
|
|
|
|
// with regards to delay while running A/B tests to anonymous users.
|
|
|
|
// When EventLogging is not available this will reject.
|
|
|
|
// This code can be removed by the end of the Desktop improvements project.
|
|
|
|
// https://www.mediawiki.org/wiki/Desktop_improvements
|
|
|
|
mw.loader.using( 'ext.eventLogging' ).then( function () {
|
|
|
|
if (
|
|
|
|
mw.eventLog &&
|
|
|
|
mw.eventLog.eventInSample( 100 /* 1 in 100 */ ) &&
|
|
|
|
window.performance &&
|
|
|
|
window.performance.timing &&
|
|
|
|
window.performance.timing.navigationStart
|
|
|
|
) {
|
|
|
|
mw.track( 'timing.Vector.ready', now - window.performance.timing.navigationStart ); // milliseconds
|
|
|
|
}
|
|
|
|
} );
|
2020-04-10 15:24:13 +00:00
|
|
|
}
|
|
|
|
|
2021-09-03 15:55:50 +00:00
|
|
|
init( window );
|
|
|
|
|
2021-10-30 01:01:36 +00:00
|
|
|
/**
|
|
|
|
* 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 );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2021-09-03 15:55:50 +00:00
|
|
|
if ( document.readyState === 'interactive' || document.readyState === 'complete' ) {
|
2021-10-30 01:01:36 +00:00
|
|
|
initAfterEs6Module();
|
2021-09-03 15:55:50 +00:00
|
|
|
} else {
|
|
|
|
// This is needed when document.readyState === 'loading'.
|
|
|
|
document.addEventListener( 'DOMContentLoaded', function () {
|
2021-10-30 01:01:36 +00:00
|
|
|
initAfterEs6Module();
|
2021-09-03 15:55:50 +00:00
|
|
|
} );
|
|
|
|
}
|