Make language count calculation only in core.js
This commit is contained in:
@@ -53,16 +53,12 @@
|
||||
</div>';
|
||||
/*jshint multistr:false */
|
||||
|
||||
$.uls = $.uls || {};
|
||||
|
||||
$.uls.utils = {};
|
||||
|
||||
/**
|
||||
* Count the number of keys in an object.
|
||||
* Works in a cross-browser way.
|
||||
* @param {Object} The object.
|
||||
*/
|
||||
$.uls.utils.objectLength = function ( obj ) {
|
||||
function objectLength ( obj ) {
|
||||
var count, key;
|
||||
|
||||
// Some old browsers don't support Object.keys
|
||||
@@ -236,7 +232,7 @@
|
||||
* Bind the UI elements with their event listeners
|
||||
*/
|
||||
listen: function () {
|
||||
var lcd, columnsOptions,
|
||||
var lcd, columnsOptions, languagesCount,
|
||||
uls = this;
|
||||
|
||||
columnsOptions = {
|
||||
@@ -263,10 +259,12 @@
|
||||
this.$menu.on( 'keydown', $.proxy( this.keypress, this ) );
|
||||
}
|
||||
|
||||
languagesCount = objectLength( this.options.languages );
|
||||
lcd = this.$resultsView.lcd( {
|
||||
languages: this.languages,
|
||||
columns: columnsOptions[ this.getMenuWidth() ],
|
||||
quickList: this.options.quickList,
|
||||
|
||||
quickList: languagesCount > 12 ? this.options.quickList : false,
|
||||
clickhandler: $.proxy( this.select, this ),
|
||||
source: this.$languageFilter,
|
||||
showRegions: this.options.showRegions,
|
||||
@@ -388,7 +386,7 @@
|
||||
return this.options.menuWidth;
|
||||
}
|
||||
|
||||
languagesCount = $.uls.utils.objectLength( this.options.languages );
|
||||
languagesCount = objectLength( this.options.languages );
|
||||
|
||||
if ( languagesCount < 12 ) {
|
||||
return 'narrow';
|
||||
|
||||
@@ -115,7 +115,6 @@
|
||||
|
||||
render: function () {
|
||||
var $section,
|
||||
languagesCount,
|
||||
lcd = this,
|
||||
regions = [],
|
||||
regionNames = {
|
||||
@@ -130,12 +129,7 @@
|
||||
PA: 'Pacific'
|
||||
};
|
||||
|
||||
languagesCount = $.uls.utils.objectLength( this.options.languages );
|
||||
|
||||
// Show the Common languages section, unless the list is very short
|
||||
if ( languagesCount > 12 ) {
|
||||
regions.push( this.buildQuicklist() );
|
||||
}
|
||||
regions.push( this.buildQuicklist() );
|
||||
|
||||
$.each( $.uls.data.regiongroups, function ( regionCode ) {
|
||||
lcd.regionLanguages[ regionCode ] = [];
|
||||
|
||||
@@ -271,26 +271,4 @@
|
||||
assert.strictEqual( $.uls.data.languages['qqq'], undefined, 'Data about qqq is undefined after being deleted.' );
|
||||
assert.ok( !$.uls.data.deleteLanguage( 'qqr' ), 'Deleting language qqr, which was never added, returns false.' );
|
||||
} );
|
||||
|
||||
test( '-- $.uls.utils testing', 4, function ( assert ) {
|
||||
var languages, saveObjectKeys;
|
||||
|
||||
languages = {
|
||||
mn: 'монгол',
|
||||
sah: 'саха',
|
||||
udm: 'удмурт'
|
||||
};
|
||||
|
||||
assert.strictEqual( $.uls.utils.objectLength( {} ), 0 );
|
||||
assert.strictEqual( $.uls.utils.objectLength( languages ), 3 );
|
||||
|
||||
// Simulate a browser without Object.keys
|
||||
saveObjectKeys = Object.keys;
|
||||
Object.keys = undefined;
|
||||
|
||||
assert.strictEqual( $.uls.utils.objectLength( {} ), 0 );
|
||||
assert.strictEqual( $.uls.utils.objectLength( languages ), 3 );
|
||||
|
||||
Object.keys = saveObjectKeys;
|
||||
} );
|
||||
}( jQuery ) );
|
||||
|
||||
Reference in New Issue
Block a user