Make language count calculation only in core.js
This commit is contained in:
@@ -53,16 +53,12 @@
|
|||||||
</div>';
|
</div>';
|
||||||
/*jshint multistr:false */
|
/*jshint multistr:false */
|
||||||
|
|
||||||
$.uls = $.uls || {};
|
|
||||||
|
|
||||||
$.uls.utils = {};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Count the number of keys in an object.
|
* Count the number of keys in an object.
|
||||||
* Works in a cross-browser way.
|
* Works in a cross-browser way.
|
||||||
* @param {Object} The object.
|
* @param {Object} The object.
|
||||||
*/
|
*/
|
||||||
$.uls.utils.objectLength = function ( obj ) {
|
function objectLength ( obj ) {
|
||||||
var count, key;
|
var count, key;
|
||||||
|
|
||||||
// Some old browsers don't support Object.keys
|
// Some old browsers don't support Object.keys
|
||||||
@@ -236,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 = {
|
||||||
@@ -263,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,
|
||||||
@@ -388,7 +386,7 @@
|
|||||||
return this.options.menuWidth;
|
return this.options.menuWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
languagesCount = $.uls.utils.objectLength( this.options.languages );
|
languagesCount = objectLength( this.options.languages );
|
||||||
|
|
||||||
if ( languagesCount < 12 ) {
|
if ( languagesCount < 12 ) {
|
||||||
return 'narrow';
|
return 'narrow';
|
||||||
|
|||||||
@@ -115,7 +115,6 @@
|
|||||||
|
|
||||||
render: function () {
|
render: function () {
|
||||||
var $section,
|
var $section,
|
||||||
languagesCount,
|
|
||||||
lcd = this,
|
lcd = this,
|
||||||
regions = [],
|
regions = [],
|
||||||
regionNames = {
|
regionNames = {
|
||||||
@@ -130,12 +129,7 @@
|
|||||||
PA: 'Pacific'
|
PA: 'Pacific'
|
||||||
};
|
};
|
||||||
|
|
||||||
languagesCount = $.uls.utils.objectLength( this.options.languages );
|
regions.push( this.buildQuicklist() );
|
||||||
|
|
||||||
// Show the Common languages section, unless the list is very short
|
|
||||||
if ( languagesCount > 12 ) {
|
|
||||||
regions.push( this.buildQuicklist() );
|
|
||||||
}
|
|
||||||
|
|
||||||
$.each( $.uls.data.regiongroups, function ( regionCode ) {
|
$.each( $.uls.data.regiongroups, function ( regionCode ) {
|
||||||
lcd.regionLanguages[ regionCode ] = [];
|
lcd.regionLanguages[ regionCode ] = [];
|
||||||
|
|||||||
@@ -271,26 +271,4 @@
|
|||||||
assert.strictEqual( $.uls.data.languages['qqq'], undefined, 'Data about qqq is undefined after being deleted.' );
|
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.' );
|
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 ) );
|
}( jQuery ) );
|
||||||
|
|||||||
Reference in New Issue
Block a user