Merge branch 'uls-remove-map' of https://github.com/santhoshtr/jquery.uls into santhoshtr-uls-remove-map

Change-Id: Ie59e2a59225873b5cf432df526cbfc135e539d32
This commit is contained in:
Santhosh Thottingal
2014-12-22 14:51:46 +05:30
10 changed files with 82 additions and 279 deletions

View File

@@ -34,14 +34,7 @@
<p>\
<span data-i18n="uls-search-help">You can search by language name, \
script name, ISO code of language or \
you can browse by region:</span>\
<a class="uls-region-link" data-i18n="uls-region-AM" data-region="AM">America</a>, \
<a class="uls-region-link" data-i18n="uls-region-EU" data-region="EU">Europe</a>, \
<a class="uls-region-link" data-i18n="uls-region-ME" data-region="ME">Middle East</a>, \
<a class="uls-region-link" data-i18n="uls-region-AF" data-region="AF">Africa</a>, \
<a class="uls-region-link" data-i18n="uls-region-AS" data-region="AS">Asia</a>, \
<a class="uls-region-link" data-i18n="uls-region-PA" data-region="PA">Pacific</a>, \
<a class="uls-region-link" data-i18n="uls-region-WW" data-region="WW">Worldwide</a>.\
you can browse by region.</span>\
</p>\
</div>\
</div>\
@@ -73,25 +66,26 @@
* @return {bool} Whether the language was added.
*/
append: function ( langCode, regionCode ) {
var lcd = this, i, regions;
var lcd = this,
i, regions;
if ( !this.options.languages[langCode] ) {
if ( !this.options.languages[ langCode ] ) {
// Language is unknown or not in the list of languages for this context.
return false;
}
// Show everything in one region when there is only one column
if ( lcd.options.columns === 1 ) {
regions = ['WW'];
regions = [ 'WW' ];
// Languages are expected to be repeated in this case,
// and we only want to show them once
if ( $.inArray( langCode, this.regionLanguages['WW'] ) > -1 ) {
if ( $.inArray( langCode, this.regionLanguages.WW ) > -1 ) {
return true;
}
} else {
if ( regionCode ) {
regions = [regionCode];
regions = [ regionCode ];
} else {
regions = $.uls.data.getRegions( langCode );
}
@@ -99,11 +93,11 @@
// Worldwides only displayed once
if ( $.inArray( 'WW', regions ) > -1 ) {
regions = ['WW'];
regions = [ 'WW' ];
}
for ( i = 0; i < regions.length; i++ ) {
this.regionLanguages[regions[i]].push( langCode );
this.regionLanguages[ regions[ i ] ].push( langCode );
}
// Work around the bad interface, delay rendering until we have got
@@ -135,9 +129,7 @@
regions.push( this.buildQuicklist() );
$.each( $.uls.data.regiongroups, function ( regionCode ) {
var $regionTitle;
lcd.regionLanguages[regionCode] = [];
lcd.regionLanguages[ regionCode ] = [];
// Don't show the region unless it was enabled
if ( $.inArray( regionCode, lcd.options.showRegions ) === -1 ) {
@@ -153,9 +145,9 @@
$section.append( $( '<h3>' )
.attr( 'data-i18n', 'uls-region-' + regionCode )
.addClass( 'eleven columns uls-lcd-region-title' )
.text( regionNames[regionCode] )
.text( regionNames[ regionCode ] )
);
};
}
regions.push( $section );
} );
@@ -183,7 +175,7 @@
$region.children( '.uls-language-block' ).remove();
languages = lcd.regionLanguages[regionCode];
languages = lcd.regionLanguages[ regionCode ];
if ( !languages || languages.length === 0 ) {
$region.addClass( 'hide' );
return;
@@ -197,7 +189,7 @@
);
$region.removeClass( 'hide' );
lcd.regionLanguages[regionCode] = [];
lcd.regionLanguages[ regionCode ] = [];
} );
},
@@ -209,7 +201,7 @@
* @param {number} itemsPerColumn How many languages fit in a column.
* @param {number} columnsPerRow How many columns fit in a row.
*/
renderRegion: function( $region, languages, itemsPerColumn, columnsPerRow ) {
renderRegion: function ( $region, languages, itemsPerColumn, columnsPerRow ) {
var columnsClasses, i, lastItem, currentScript, nextScript, force,
languagesCount = languages.length,
items = [],
@@ -228,7 +220,7 @@
// For one-column narrow ULS, just render all the languages
// in one simple list without separators or script groups
for ( i = 0; i < languagesCount; i++ ) {
items.push( this.renderItem( languages[i] ) );
items.push( this.renderItem( languages[ i ] ) );
}
columns.push( $( '<ul>' ).addClass( columnsClasses ).append( items ) );
@@ -237,23 +229,22 @@
// For medium and wide ULS, clever column placement
for ( i = 0; i < languagesCount; i++ ) {
force = false;
nextScript = $.uls.data.getScriptGroupOfLanguage( languages[i+1] );
nextScript = $.uls.data.getScriptGroupOfLanguage( languages[ i + 1 ] );
lastItem = languagesCount - i === 1;
// Force column break if script changes and column has more than one row already
if ( i === 0 ) {
currentScript = $.uls.data.getScriptGroupOfLanguage( languages[i] );
currentScript = $.uls.data.getScriptGroupOfLanguage( languages[ i ] );
} else if ( currentScript !== nextScript && items.length > 1 ) {
force = true;
}
currentScript = nextScript;
items.push( this.renderItem( languages[i] ) );
items.push( this.renderItem( languages[ i ] ) );
if ( items.length >= itemsPerColumn || lastItem || force ) {
columns.push( $( '<ul>' ).addClass( columnsClasses ).append( items ) );
items = [];
if ( columns.length >= columnsPerRow || lastItem ) {
rows.push( $( '<div>' ).addClass( 'row uls-language-block' ).append( columns ) );
columns = [];
@@ -270,10 +261,10 @@
* @param {string} code Language code
* @return {Element}
*/
renderItem: function( code ) {
renderItem: function ( code ) {
var a, name, autonym, li;
name = this.options.languages[code];
name = this.options.languages[ code ];
autonym = $.uls.data.getAutonym( code ) || name || code;
// Not using jQuery as this is performance hotspot
@@ -294,7 +285,7 @@
return li;
},
i18n: function ( ) {
i18n: function () {
this.$element.find( '[data-i18n]' ).i18n();
},
@@ -407,7 +398,7 @@
} );
// highlight the region visible while scrolling in the map.
inview = $.uls.data.regiongroups[inviewRegion];
inview = $.uls.data.regiongroups[ inviewRegion ];
if ( !$( '#uls-region-' + inview ).hasClass( 'active' ) ) {
$( '.regionselector' ).removeClass( 'active' );
$( '#uls-region-' + inview ).addClass( 'active' );
@@ -426,15 +417,15 @@
$this.data( 'lcd', ( data = new LanguageCategoryDisplay( this, options ) ) );
}
if ( typeof option === 'string') {
data[option]();
if ( typeof option === 'string' ) {
data[ option ]();
}
} );
};
$.fn.lcd.defaults = {
languages: null,
showRegions: ['WW', 'AM', 'EU', 'ME', 'AF', 'AS', 'PA'],
showRegions: [ 'WW', 'AM', 'EU', 'ME', 'AF', 'AS', 'PA' ],
itemsPerColumn: 8,
// Other supported values are 1 and 2.
// Other values will have rendering issues.
@@ -443,4 +434,4 @@
};
$.fn.lcd.Constructor = LanguageCategoryDisplay;
} ( jQuery ) );
}( jQuery ) );