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' ),
|
var collapsibleTabs = require( '../skins.vector.legacy.js/collapsibleTabs.js' ),
|
||||||
vector = require( '../skins.vector.legacy.js/vector.js' ),
|
vector = require( '../skins.vector.legacy.js/vector.js' ),
|
||||||
|
languageButton = require( './languageButton.js' ),
|
||||||
initSearchLoader = require( './searchLoader.js' ).initSearchLoader,
|
initSearchLoader = require( './searchLoader.js' ).initSearchLoader,
|
||||||
sidebar = require( './sidebar.js' );
|
sidebar = require( './sidebar.js' );
|
||||||
|
|
||||||
|
@ -40,34 +41,12 @@ function enableCssAnimations( document ) {
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
function main( window ) {
|
function main( window ) {
|
||||||
var
|
|
||||||
ulsModuleStatus = mw.loader.getState( 'ext.uls.interface' ),
|
|
||||||
pLangBtnLabel;
|
|
||||||
|
|
||||||
enableCssAnimations( window.document );
|
enableCssAnimations( window.document );
|
||||||
collapsibleTabs.init();
|
collapsibleTabs.init();
|
||||||
sidebar.init( window );
|
sidebar.init( window );
|
||||||
$( vector.init );
|
$( vector.init );
|
||||||
initSearchLoader( document );
|
initSearchLoader( document );
|
||||||
if ( ulsModuleStatus && ulsModuleStatus !== 'registered' ) {
|
languageButton();
|
||||||
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 );
|
main( window );
|
||||||
|
|
|
@ -148,6 +148,7 @@
|
||||||
"resources/skins.vector.js/sidebar.js",
|
"resources/skins.vector.js/sidebar.js",
|
||||||
"resources/skins.vector.legacy.js/collapsibleTabs.js",
|
"resources/skins.vector.legacy.js/collapsibleTabs.js",
|
||||||
"resources/skins.vector.legacy.js/vector.js",
|
"resources/skins.vector.legacy.js/vector.js",
|
||||||
|
"resources/skins.vector.js/languageButton.js",
|
||||||
"resources/skins.vector.js/searchLoader.js"
|
"resources/skins.vector.js/searchLoader.js"
|
||||||
],
|
],
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
|
|
Loading…
Reference in New Issue