Refactor: Separate Language button code into its own JS file
Having this outside the init function makes the code more easy to understand. Change-Id: I6bdcb385738ceb986e21075b006db40567386e7b
This commit is contained in:
parent
9bdd6c0130
commit
1d01f70e32
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* 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 ( 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' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the language button.
|
||||
*/
|
||||
module.exports = function () {
|
||||
disableLanguageDropdown();
|
||||
};
|
|
@ -1,5 +1,6 @@
|
|||
var collapsibleTabs = require( '../skins.vector.legacy.js/collapsibleTabs.js' ),
|
||||
vector = require( '../skins.vector.legacy.js/vector.js' ),
|
||||
languageButton = require( './languageButton.js' ),
|
||||
initSearchLoader = require( './searchLoader.js' ).initSearchLoader,
|
||||
sidebar = require( './sidebar.js' );
|
||||
|
||||
|
@ -40,34 +41,12 @@ function enableCssAnimations( document ) {
|
|||
* @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' );
|
||||
}
|
||||
languageButton();
|
||||
}
|
||||
|
||||
main( window );
|
||||
|
|
Loading…
Reference in New Issue