Do not rely on load order for disabling language button fallback
Some code disables the dropdown behaviour when ULS is loaded, however it does not always appear to be working as the `ext.uls.interface` module may be loaded for other things unrelated to the compact languages link button. The safest thing to do for now seems to be to check the configuration flag wgULSisCompactLinksEnabled. In future, perhaps a hook event could be added to ULS and that could be subscribed to instead. Bug: T287191 Change-Id: I0cf8d387919078aabc9e77a0a452f8b3364016ee
This commit is contained in:
parent
d3f09a1c3d
commit
85ffc0805e
|
@ -15,6 +15,19 @@ function addInterwikiLinkToSidebar() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable dropdown behaviour for non-JS users.
|
||||
*
|
||||
* @param {HTMLElement|null} pLangBtn
|
||||
* @return {void}
|
||||
*/
|
||||
function disableDropdownBehavior( pLangBtn ) {
|
||||
if ( !pLangBtn ) {
|
||||
return;
|
||||
}
|
||||
pLangBtn.classList.add( 'vector-menu--hide-dropdown' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether ULS is enabled and if so disables the default
|
||||
* drop down behavior of the button.
|
||||
|
@ -23,19 +36,13 @@ function disableLanguageDropdown() {
|
|||
var ulsModuleStatus = mw.loader.getState( 'ext.uls.interface' ),
|
||||
pLangBtnLabel;
|
||||
|
||||
// If module status is defined and not registered we can assume it is in the process of loading
|
||||
if ( ulsModuleStatus && ulsModuleStatus !== 'registered' ) {
|
||||
mw.loader.using( 'ext.uls.interface' ).then( function () {
|
||||
var pLangBtn = document.getElementById( 'p-lang-btn' );
|
||||
if ( !pLangBtn ) {
|
||||
return;
|
||||
}
|
||||
if ( !pLangBtn.querySelectorAll( '.mw-interlanguage-selector' ).length ) {
|
||||
// The ext.uls.interface module removed the selector,
|
||||
// because the feature is disabled. Do nothing.
|
||||
return;
|
||||
}
|
||||
pLangBtn.classList.add( 'vector-menu--hide-dropdown' );
|
||||
} );
|
||||
// HACK: Ideally knowledge of internal ULS configuration would not be necessary
|
||||
// In future this should be wired up to an `mw.hook` event.
|
||||
if ( mw.config.get( 'wgULSisCompactLinksEnabled' ) ) {
|
||||
disableDropdownBehavior( document.getElementById( 'p-lang-btn' ) );
|
||||
}
|
||||
} else {
|
||||
pLangBtnLabel = document.getElementById( 'p-lang-btn-label' );
|
||||
if ( !pLangBtnLabel ) {
|
||||
|
|
Loading…
Reference in New Issue