2021-07-26 21:00:38 +00:00
|
|
|
/**
|
|
|
|
* 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' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-26 19:57:53 +00:00
|
|
|
/**
|
|
|
|
* 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' );
|
|
|
|
}
|
|
|
|
|
2021-03-01 21:32:25 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2021-07-26 19:57:53 +00:00
|
|
|
// If module status is defined and not registered we can assume it is in the process of loading
|
2021-03-01 21:32:25 +00:00
|
|
|
if ( ulsModuleStatus && ulsModuleStatus !== 'registered' ) {
|
2021-07-26 19:57:53 +00:00
|
|
|
// 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' ) );
|
|
|
|
}
|
2021-03-01 21:32:25 +00:00
|
|
|
} 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();
|
2021-07-26 21:00:38 +00:00
|
|
|
addInterwikiLinkToSidebar();
|
2021-03-01 21:32:25 +00:00
|
|
|
};
|