mediawiki-skins-Vector/resources/skins.vector.js/skin.js
Nicholas Ray e3abac06a6 Add mw-interlanguage-selector class to language button & hide menu/arrow when appropriate
* We add the `.mw-interlanguage-selector` class to the
.vector-menu-heading in the server rendered HTML. `ext.uls.interface.js`
later attaches a click handler to this selector that loads the rest of
ULS.

* We hide the dropdown arrow for js users and only show it again if
ext.uls.interface module isn't installed or is not being loaded.

* When the `ext.uls.interface` module has been loaded, we hide the checkbox
and checkbox hack menu in favor of showing the ULS popover.

Additionally:

* Adds '.vector-menu-heading' class to menu headings.

* Change h3 selector to `.vector-menu-heading`.

Bug: T273232
Change-Id: I6f4572c16ca4096dcda3aac4d585003b93dcccfa
2021-02-05 15:03:07 -07:00

74 lines
2.2 KiB
JavaScript

var collapsibleTabs = require( '../skins.vector.legacy.js/collapsibleTabs.js' ),
vector = require( '../skins.vector.legacy.js/vector.js' ),
initSearchLoader = require( './searchLoader.js' ).initSearchLoader,
sidebar = require( './sidebar.js' );
/**
* 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;
* .transform( translateX( -100% ) );
* }
*
* // This transition will be disabled initially for JavaScript users. It will never be enabled for
* // no-JS users.
* .vector-animations-ready .foo {
* .transition( transform 100ms ease-out; );
* }
* ```
*
* @param {Document} document
* @return {void}
*/
function enableCssAnimations( document ) {
document.documentElement.classList.add( 'vector-animations-ready' );
}
/**
* @param {Window} window
* @return {void}
*/
function main( window ) {
var
ulsModuleStatus = mw.loader.getState( 'ext.uls.interface' ),
pLangBtnLabel;
enableCssAnimations( window.document );
collapsibleTabs.init();
sidebar.init( window );
$( vector.init );
initSearchLoader( document );
if ( ulsModuleStatus && ulsModuleStatus !== 'registered' ) {
mw.loader.using( 'ext.uls.interface' ).then( function () {
var pLangBtn = document.getElementById( 'p-lang-btn' );
if ( !pLangBtn ) {
return;
}
pLangBtn.classList.add( 'vector-menu--hide-dropdown' );
} );
} else {
pLangBtnLabel = document.getElementById( 'p-lang-btn-label' );
if ( !pLangBtnLabel ) {
return;
}
// Remove .mw-interlanguage-selector to show the dropdown arrow since evidently
// ULS is not used.
pLangBtnLabel.classList.remove( 'mw-interlanguage-selector' );
}
}
main( window );