Update jquery.uls to 4cb4fe2

* Fix search for languages with redirects
* Use Array.prototype.indexOf instead of $.inArray

Bug: T178996
Change-Id: Id0ac6233544f827ca69c5ebd4965532d6dbf3227
This commit is contained in:
petarpetkovic
2018-02-08 16:48:07 +01:00
parent d256bb4594
commit e4f6b4e3b6
2 changed files with 25 additions and 6 deletions

View File

@@ -183,7 +183,7 @@
}
for ( i = 0; i < regions.length; i++ ) {
if ( $.inArray( regions[ i ], $.uls.data.getRegions( language ) ) !== -1 ) {
if ( $.uls.data.getRegions( language ).indexOf( regions[ i ] ) !== -1 ) {
scriptGroup = $.uls.data.getScriptGroupOfLanguage( language );
if ( languagesByScriptGroupInRegions[ scriptGroup ] === undefined ) {
@@ -209,7 +209,7 @@
var scriptGroup;
for ( scriptGroup in $.uls.data.scriptgroups ) {
if ( $.inArray( script, $.uls.data.scriptgroups[ scriptGroup ] ) !== -1 ) {
if ( $.uls.data.scriptgroups[ scriptGroup ].indexOf( script ) !== -1 ) {
return scriptGroup;
}
}
@@ -246,7 +246,7 @@
* @return {boolean}
*/
$.uls.data.isRtl = function ( language ) {
return $.inArray( $.uls.data.getScript( language ), $.uls.data.rtlscripts ) !== -1;
return $.uls.data.rtlscripts.indexOf( $.uls.data.getScript( language ) ) !== -1;
};
/**

View File

@@ -192,15 +192,34 @@
var autofillLabel,
results = [];
$.each( result.languagesearch, function ( code, name ) {
if ( this.options.languages[ code ] ) {
$.each( result.languagesearch, function ( apiCode, name ) {
var code, redirect;
if ( this.options.languages[ apiCode ] ) {
code = apiCode;
} else {
redirect = $.uls.data.isRedirect( apiCode );
if ( !redirect || !this.options.languages[ redirect ] ) {
return;
}
code = redirect;
}
// Because of the redirect checking above, we might get duplicates.
// For example if API returns both `sr` and `sr-cyrl`, the former
// could get mapped to `sr-cyrl` and then we would have it twice.
// The exact cases when this happens of course depends on what is in
// options.languages, which might contain redirects such as `sr`. In
// this case we only show `sr` if no other variants are there.
// This also protects against broken search APIs returning duplicate
// results, although that is not happening in practice.
if ( results.indexOf( code ) === -1 ) {
autofillLabel = autofillLabel || name;
results.push( code );
}
}.bind( this ) );
return $.Deferred().resolve( query, results, autofillLabel );
}.bind( this ) );
},