mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-09-24 18:59:24 +00:00
85ffc0805e
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
65 lines
1.8 KiB
JavaScript
65 lines
1.8 KiB
JavaScript
/**
|
|
* Copies interwiki links to sidebar
|
|
*
|
|
* Temporary solution to T287206, can be removed when the new ULS built in Vue.js
|
|
* has been released and contains this
|
|
*/
|
|
function addInterwikiLinkToSidebar() {
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
|
var $editLink = $( '#p-lang-btn .wbc-editpage' );
|
|
if ( $editLink.length ) {
|
|
// Use title attribute for link text
|
|
$editLink.text( $editLink.attr( 'title' ) || '' );
|
|
var $li = $( '<li>' ).append( $editLink );
|
|
$li.appendTo( '#p-tb ul' );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
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' ) {
|
|
// 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 ) {
|
|
return;
|
|
}
|
|
|
|
// Remove .mw-interlanguage-selector to show the dropdown arrow since evidently
|
|
// ULS is not used.
|
|
pLangBtnLabel.classList.remove( 'mw-interlanguage-selector' );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Initialize the language button.
|
|
*/
|
|
module.exports = function () {
|
|
disableLanguageDropdown();
|
|
addInterwikiLinkToSidebar();
|
|
};
|