Push selected language to previous languages list
Bug: 62692 Change-Id: I3b40ed1038cec0b34d3b0fbefcae4d4ae650ce36
This commit is contained in:
@@ -93,6 +93,14 @@
|
||||
return commonLanguages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push the selected language into the previous languages list
|
||||
* @param {string} Language code of language selected (clicked on)
|
||||
*/
|
||||
function insertPreviousLanguage( currentLang ) {
|
||||
mw.uls.insertPreviousLanguage( currentLang );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a ULS trigger beneath the interlanguage links
|
||||
*/
|
||||
@@ -118,6 +126,8 @@
|
||||
|
||||
onSelect: function( language ) {
|
||||
supportedLangs = getInterlanguageList();
|
||||
// To set selected language as a previous language
|
||||
insertPreviousLanguage( language );
|
||||
window.location.href = supportedLangs[language];
|
||||
},
|
||||
|
||||
@@ -145,20 +155,34 @@
|
||||
*/
|
||||
function displayLanguages( numberOfLanguagesToShow ) {
|
||||
var commonLang = getCommonLanguages(),
|
||||
currentLangs = getInterlanguageList(), i,
|
||||
acceptedLangs = $.map( getCurrentLanguages(), function ( element, index ) {
|
||||
return index;
|
||||
} ), i,
|
||||
prevLangs = mw.uls.getPreviousLanguages(),
|
||||
count,
|
||||
finalList = [];
|
||||
|
||||
// Check existing languages for ones in common, and add them to final list
|
||||
// Add languages in the common list and accepted by article
|
||||
for ( i = 0; i < commonLang.length; i++ ) {
|
||||
finalList.push( commonLang[i] );
|
||||
}
|
||||
|
||||
count = commonLang.length;
|
||||
// Add languages in previous choices to list if not already in it
|
||||
for ( i = 0; i < prevLangs.length; i++ ) {
|
||||
if (
|
||||
$.inArray( prevLangs[i], finalList ) < 0 &&
|
||||
$.inArray( prevLangs[i], acceptedLangs ) >= 0
|
||||
) {
|
||||
finalList.push( prevLangs[i] );
|
||||
}
|
||||
}
|
||||
|
||||
// Add random languages to make the language list long enough, if it isn't already
|
||||
count = finalList.length;
|
||||
if ( count < numberOfLanguagesToShow ) {
|
||||
for ( i in currentLangs ) {
|
||||
if ( $.inArray( i, commonLang ) === -1 ) {
|
||||
finalList.push( i );
|
||||
for ( i = 0; i < acceptedLangs.length; i++ ) {
|
||||
if ( $.inArray( acceptedLangs[i], finalList ) < 0 ) {
|
||||
finalList.push( acceptedLangs[i] );
|
||||
count++;
|
||||
if ( count === numberOfLanguagesToShow ) {
|
||||
break;
|
||||
|
||||
@@ -120,6 +120,25 @@
|
||||
return $.parseJSON( previousLanguages ).slice( -5 );
|
||||
};
|
||||
|
||||
/**
|
||||
* Push the selected language into the previous languages list
|
||||
* if it isn't there already
|
||||
* @param {string} Language code of language to be pushed into list
|
||||
*/
|
||||
mw.uls.insertPreviousLanguage = function ( prevLangCode ) {
|
||||
var previousLanguages = mw.uls.getPreviousLanguages() || [],
|
||||
currentLangIndex;
|
||||
// Checking if it already exists in array
|
||||
currentLangIndex = $.inArray( prevLangCode, previousLanguages );
|
||||
if ( currentLangIndex < 0 ) {
|
||||
previousLanguages.push( prevLangCode );
|
||||
} else {
|
||||
previousLanguages.splice( currentLangIndex, 1 );
|
||||
previousLanguages.push( prevLangCode );
|
||||
}
|
||||
mw.uls.setPreviousLanguages( previousLanguages );
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the browser's user interface language or the system language.
|
||||
* The caller should check the validity of the returned language code.
|
||||
|
||||
Reference in New Issue
Block a user