Separate compacting of language list from launching of dialog

This refactor will allow us to separate these two functions so that
the modernized version of Vector can avoid loading the compact
language list.

Changes:
* `options` is now optional to the CompactInterlanguageList constructor
The max value is already defined in
CompactInterlanguageList.prototype.init
* this.interlanguageList is now initialized inside the constructor
Previously calling CompactInterlanguageList.prototype.createSelector
or getCompactList before calling init would throw an exception.
This will be important in I0518ecdf402ebf5eb6bad2c430f6462322c0d8e1 when
the responsibilities of wiring up the button and compacting the languages
is separated.

Bug: T264824
Change-Id: I9606df30a050d0cdaf7add2deff849cd5b895bab
This commit is contained in:
jdlrobson
2020-10-21 16:53:48 -07:00
committed by jenkins-bot
parent 7ed148646d
commit e3569d32a7
4 changed files with 177 additions and 126 deletions

View File

@@ -103,6 +103,35 @@
} catch ( e ) {}
};
/**
* Normalize a language code for ULS usage.
*
* MediaWiki language codes (especially on WMF sites) are inconsistent
* with ULS codes. We need to use ULS codes to access the proper data.
*
* @param {string} code
* @return {string} Normalized language code
*/
mw.uls.convertMediaWikiLanguageCodeToULS = function ( code ) {
code = code.toLowerCase();
return $.uls.data.isRedirect( code ) || code;
};
/**
* @param {Element[]} nodes to parse
* @return {Object} that maps language codes to the corresponding DOM elements
*/
mw.uls.getInterlanguageListFromNodes = function ( nodes ) {
var interlanguageList = {};
Array.prototype.forEach.call( nodes, function ( el ) {
var langCode = mw.uls.convertMediaWikiLanguageCodeToULS( el.lang );
interlanguageList[ langCode ] = el;
} );
return interlanguageList;
};
mw.uls.getPreviousLanguages = function () {
var previousLanguages = [];