Update jquery.uls from upstream

To github version:
345097a8bd

Show the Common language section only if the list is long enough

Bug: T76196
Change-Id: I6aa0d951657962103c356f6254ab4102e5ee765d
This commit is contained in:
Amir E. Aharoni
2015-04-08 14:53:12 +03:00
committed by Amire80
parent 7661826ff1
commit e65202b434

View File

@@ -53,6 +53,30 @@
</div>'; </div>';
/*jshint multistr:false */ /*jshint multistr:false */
/**
* Count the number of keys in an object.
* Works in a cross-browser way.
* @param {Object} The object.
*/
function objectLength ( obj ) {
var count, key;
// Some old browsers don't support Object.keys
if ( Object.keys ) {
return Object.keys( obj ).length;
}
count = 0;
for ( key in obj ) {
if ( Object.prototype.hasOwnProperty.call( obj, key ) ) {
count++;
}
}
return count;
}
/** /**
* ULS Public class definition * ULS Public class definition
*/ */
@@ -208,7 +232,7 @@
* Bind the UI elements with their event listeners * Bind the UI elements with their event listeners
*/ */
listen: function () { listen: function () {
var lcd, columnsOptions, var lcd, columnsOptions, languagesCount,
uls = this; uls = this;
columnsOptions = { columnsOptions = {
@@ -235,10 +259,12 @@
this.$menu.on( 'keydown', $.proxy( this.keypress, this ) ); this.$menu.on( 'keydown', $.proxy( this.keypress, this ) );
} }
languagesCount = objectLength( this.options.languages );
lcd = this.$resultsView.lcd( { lcd = this.$resultsView.lcd( {
languages: this.languages, languages: this.languages,
columns: columnsOptions[ this.getMenuWidth() ], columns: columnsOptions[ this.getMenuWidth() ],
quickList: this.options.quickList,
quickList: languagesCount > 12 ? this.options.quickList : false,
clickhandler: $.proxy( this.select, this ), clickhandler: $.proxy( this.select, this ),
source: this.$languageFilter, source: this.$languageFilter,
showRegions: this.options.showRegions, showRegions: this.options.showRegions,
@@ -354,26 +380,13 @@
* @return string * @return string
*/ */
getMenuWidth: function () { getMenuWidth: function () {
var language, var languagesCount;
languagesCount = 0;
if ( this.options.menuWidth ) { if ( this.options.menuWidth ) {
return this.options.menuWidth; return this.options.menuWidth;
} }
// IE8 does not support Object.keys languagesCount = objectLength( this.options.languages );
if ( Object.keys ) {
languagesCount = Object.keys( this.options.languages ).length;
} else {
for ( language in this.options.languages ) {
if ( Object.prototype.hasOwnProperty.call(
this.options.languages,
language
) ) {
languagesCount++;
}
}
}
if ( languagesCount < 12 ) { if ( languagesCount < 12 ) {
return 'narrow'; return 'narrow';