Whitespace
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
* @param language string Language code
|
||||
* @return Target language code if it's a redirect or false if it's not
|
||||
*/
|
||||
$.uls.data.isRedirect = function( language ) {
|
||||
$.uls.data.isRedirect = function ( language ) {
|
||||
return ( $.uls.data.languages[language] !== undefined &&
|
||||
$.uls.data.languages[language].length === 1 ) ? $.uls.data.languages[language][0] : false;
|
||||
};
|
||||
@@ -35,7 +35,7 @@
|
||||
* @param language string Language code
|
||||
* @return string
|
||||
*/
|
||||
$.uls.data.getScript = function( language ) {
|
||||
$.uls.data.getScript = function ( language ) {
|
||||
var target = $.uls.data.isRedirect( language );
|
||||
|
||||
if ( target ) {
|
||||
@@ -50,7 +50,7 @@
|
||||
* @param language string Language code
|
||||
* @return array|string 'UNKNOWN'
|
||||
*/
|
||||
$.uls.data.getRegions = function( language ) {
|
||||
$.uls.data.getRegions = function ( language ) {
|
||||
var target = $.uls.data.isRedirect( language );
|
||||
|
||||
if ( target ) {
|
||||
@@ -65,7 +65,7 @@
|
||||
* @param language string Language code
|
||||
* @return string
|
||||
*/
|
||||
$.uls.data.getAutonym = function( language ) {
|
||||
$.uls.data.getAutonym = function ( language ) {
|
||||
var target = $.uls.data.isRedirect( language );
|
||||
|
||||
if ( target ) {
|
||||
@@ -79,7 +79,7 @@
|
||||
* Returns all language codes and corresponding autonyms
|
||||
* @return array
|
||||
*/
|
||||
$.uls.data.getAutonyms = function() {
|
||||
$.uls.data.getAutonyms = function () {
|
||||
var autonymsByCode = {};
|
||||
|
||||
for ( var language in $.uls.data.languages ) {
|
||||
@@ -97,10 +97,10 @@
|
||||
* Returns an array of all region codes.
|
||||
* @return array
|
||||
*/
|
||||
$.uls.data.getAllRegions = function() {
|
||||
$.uls.data.getAllRegions = function () {
|
||||
var allRegions = [];
|
||||
|
||||
for( var region in $.uls.data.regiongroups ) {
|
||||
for ( var region in $.uls.data.regiongroups ) {
|
||||
allRegions.push( region );
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@
|
||||
* @param script string
|
||||
* @return array of strings (languages codes)
|
||||
*/
|
||||
$.uls.data.getLanguagesInScript = function( script ) {
|
||||
$.uls.data.getLanguagesInScript = function ( script ) {
|
||||
return $.uls.data.getLanguagesInScripts( [ script ] );
|
||||
};
|
||||
|
||||
@@ -122,7 +122,7 @@
|
||||
* @param scripts array of strings
|
||||
* @return array of strings (languages codes)
|
||||
*/
|
||||
$.uls.data.getLanguagesInScripts = function( scripts ) {
|
||||
$.uls.data.getLanguagesInScripts = function ( scripts ) {
|
||||
var languagesInScripts = [];
|
||||
|
||||
for ( var language in $.uls.data.languages ) {
|
||||
@@ -146,7 +146,7 @@
|
||||
* @param region string
|
||||
* @return array of strings (languages codes)
|
||||
*/
|
||||
$.uls.data.getLanguagesInRegion = function( region ) {
|
||||
$.uls.data.getLanguagesInRegion = function ( region ) {
|
||||
return $.uls.data.getLanguagesInRegions( [ region ] );
|
||||
};
|
||||
|
||||
@@ -155,7 +155,7 @@
|
||||
* @param regions array of strings.
|
||||
* @return array of strings (languages codes)
|
||||
*/
|
||||
$.uls.data.getLanguagesInRegions = function( regions ) {
|
||||
$.uls.data.getLanguagesInRegions = function ( regions ) {
|
||||
var languagesInRegions = [];
|
||||
|
||||
for ( var language in $.uls.data.languages ) {
|
||||
@@ -179,7 +179,7 @@
|
||||
* @param groupNum number.
|
||||
* @return array of strings (languages codes)
|
||||
*/
|
||||
$.uls.data.getLanguagesInRegionGroup = function( groupNum ) {
|
||||
$.uls.data.getLanguagesInRegionGroup = function ( groupNum ) {
|
||||
return $.uls.data.getLanguagesInRegions( $.uls.data.getRegionsInGroup( groupNum ) );
|
||||
};
|
||||
|
||||
@@ -189,7 +189,7 @@
|
||||
* @param region string Region code
|
||||
* @return associative array
|
||||
*/
|
||||
$.uls.data.getLanguagesByScriptInRegion = function( region ) {
|
||||
$.uls.data.getLanguagesByScriptInRegion = function ( region ) {
|
||||
var languagesByScriptInRegion = {};
|
||||
|
||||
for ( var language in $.uls.data.languages ) {
|
||||
@@ -199,6 +199,7 @@
|
||||
|
||||
if ( $.inArray( region, $.uls.data.getRegions( language ) ) !== -1 ) {
|
||||
var script = $.uls.data.getScript( language );
|
||||
|
||||
if ( languagesByScriptInRegion[script] === undefined ) {
|
||||
languagesByScriptInRegion[script] = [];
|
||||
}
|
||||
@@ -215,7 +216,7 @@
|
||||
* @param region string Region code
|
||||
* @return associative array
|
||||
*/
|
||||
$.uls.data.getLanguagesByScriptGroupInRegion = function( region ) {
|
||||
$.uls.data.getLanguagesByScriptGroupInRegion = function ( region ) {
|
||||
return $.uls.data.getLanguagesByScriptGroupInRegions( [ region ] );
|
||||
};
|
||||
|
||||
@@ -225,7 +226,7 @@
|
||||
* grouped by script group.
|
||||
* @return associative array
|
||||
*/
|
||||
$.uls.data.getAllLanguagesByScriptGroup = function() {
|
||||
$.uls.data.getAllLanguagesByScriptGroup = function () {
|
||||
return $.uls.data.getLanguagesByScriptGroupInRegions( $.uls.data.getAllRegions() );
|
||||
};
|
||||
|
||||
@@ -234,7 +235,7 @@
|
||||
* @param languages Array of language codes
|
||||
* @return {Object} Array of languages indexed by script codes
|
||||
*/
|
||||
$.uls.data.getLanguagesByScriptGroup = function( languages ) {
|
||||
$.uls.data.getLanguagesByScriptGroup = function ( languages ) {
|
||||
var languagesByScriptGroup = {},
|
||||
scriptGroup,
|
||||
language,
|
||||
@@ -243,12 +244,15 @@
|
||||
for ( scriptGroup in $.uls.data.scriptgroups ) {
|
||||
for ( language in languages ) {
|
||||
langScriptGroup = $.uls.data.getScriptGroupOfLanguage( language );
|
||||
if( langScriptGroup !== scriptGroup ) {
|
||||
|
||||
if ( langScriptGroup !== scriptGroup ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( !languagesByScriptGroup[scriptGroup] ) {
|
||||
languagesByScriptGroup[scriptGroup] = [];
|
||||
}
|
||||
|
||||
languagesByScriptGroup[scriptGroup].push( language );
|
||||
}
|
||||
}
|
||||
@@ -262,7 +266,7 @@
|
||||
* @param regions array of strings - region codes
|
||||
* @return associative array
|
||||
*/
|
||||
$.uls.data.getLanguagesByScriptGroupInRegions = function( regions ) {
|
||||
$.uls.data.getLanguagesByScriptGroupInRegions = function ( regions ) {
|
||||
var languagesByScriptGroupInRegions = {};
|
||||
|
||||
for ( var language in $.uls.data.languages ) {
|
||||
@@ -292,7 +296,7 @@
|
||||
* region, script group and script.
|
||||
* @return associative array
|
||||
*/
|
||||
$.uls.data.getAllLanguagesByRegionAndScript = function() {
|
||||
$.uls.data.getAllLanguagesByRegionAndScript = function () {
|
||||
var allLanguagesByRegionAndScript = {},
|
||||
region,
|
||||
regionGroup;
|
||||
@@ -340,7 +344,7 @@
|
||||
* @param groupNum int
|
||||
* @return array of strings
|
||||
*/
|
||||
$.uls.data.getRegionsInGroup = function( groupNum ) {
|
||||
$.uls.data.getRegionsInGroup = function ( groupNum ) {
|
||||
var regionsInGroup = [];
|
||||
|
||||
for ( var region in $.uls.data.regiongroups ) {
|
||||
@@ -359,7 +363,7 @@
|
||||
* @param script string Script code
|
||||
* @return string script group name
|
||||
*/
|
||||
$.uls.data.getGroupOfScript = function( script ) {
|
||||
$.uls.data.getGroupOfScript = function ( script ) {
|
||||
for ( var group in $.uls.data.scriptgroups ) {
|
||||
if ( $.inArray( script, $.uls.data.scriptgroups[group] ) !== -1 ) {
|
||||
return group;
|
||||
@@ -374,7 +378,7 @@
|
||||
* @param language string Language code
|
||||
* @return string script group name
|
||||
*/
|
||||
$.uls.data.getScriptGroupOfLanguage = function( language ) {
|
||||
$.uls.data.getScriptGroupOfLanguage = function ( language ) {
|
||||
return $.uls.data.getGroupOfScript( $.uls.data.getScript( language ) );
|
||||
};
|
||||
|
||||
@@ -384,9 +388,10 @@
|
||||
* @param a string Language code
|
||||
* @param b string Language code
|
||||
*/
|
||||
$.uls.data.sortByAutonym = function( a, b ) {
|
||||
$.uls.data.sortByAutonym = function ( a, b ) {
|
||||
var autonymA = $.uls.data.getAutonym( a ) || a,
|
||||
autonymB = $.uls.data.getAutonym( b ) || b;
|
||||
|
||||
return ( autonymA.toLowerCase() < autonymB.toLowerCase() ) ? -1 : 1;
|
||||
};
|
||||
|
||||
@@ -395,7 +400,7 @@
|
||||
* @param language string Language code
|
||||
* @return boolean
|
||||
*/
|
||||
$.uls.data.isRtl = function( language ) {
|
||||
$.uls.data.isRtl = function ( language ) {
|
||||
return $.inArray( $.uls.data.getScript( language ), $.uls.data.rtlscripts ) !== -1;
|
||||
};
|
||||
|
||||
@@ -404,7 +409,7 @@
|
||||
* @param language string Language code
|
||||
* @return string
|
||||
*/
|
||||
$.uls.data.getDir = function( language ) {
|
||||
$.uls.data.getDir = function ( language ) {
|
||||
return $.uls.data.isRtl( language ) ? 'rtl' : 'ltr';
|
||||
};
|
||||
|
||||
@@ -413,8 +418,7 @@
|
||||
* @param territory string Territory code
|
||||
* @return list of language codes
|
||||
*/
|
||||
$.uls.data.getLanguagesInTerritory = function( territory ) {
|
||||
$.uls.data.getLanguagesInTerritory = function ( territory ) {
|
||||
return $.uls.data.territories[territory];
|
||||
};
|
||||
|
||||
} ( jQuery ) );
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
* @licence MIT License
|
||||
*/
|
||||
|
||||
( function( $ ) {
|
||||
"use strict";
|
||||
( function ( $ ) {
|
||||
'use strict';
|
||||
|
||||
var noResultsTemplate = '\
|
||||
<div class="twelve columns uls-no-results-view">\
|
||||
@@ -45,12 +45,12 @@
|
||||
</div>\
|
||||
</div>';
|
||||
|
||||
var LanguageCategoryDisplay = function( element, options ) {
|
||||
var LanguageCategoryDisplay = function ( element, options ) {
|
||||
this.$element = $( element );
|
||||
this.options = $.extend( {}, $.fn.lcd.defaults, options );
|
||||
this.$element.addClass( 'lcd' );
|
||||
this.regionDivs = {};
|
||||
this.$element.append( $(noResultsTemplate) );
|
||||
this.$element.append( $( noResultsTemplate ) );
|
||||
this.$noResults = this.$element.find( 'div.uls-no-results-view' );
|
||||
this.render();
|
||||
this.listen();
|
||||
@@ -59,7 +59,7 @@
|
||||
LanguageCategoryDisplay.prototype = {
|
||||
constructor: LanguageCategoryDisplay,
|
||||
|
||||
append: function( langCode, regionCode ) {
|
||||
append: function ( langCode, regionCode ) {
|
||||
this.addToRegion( langCode, regionCode );
|
||||
this.$noResults.hide();
|
||||
},
|
||||
@@ -71,7 +71,7 @@
|
||||
* @param langCode
|
||||
* @param region Optional region
|
||||
*/
|
||||
addToRegion: function( langCode, region ) {
|
||||
addToRegion: function ( langCode, region ) {
|
||||
var lcd = this,
|
||||
language = lcd.options.languages[langCode],
|
||||
langName = $.uls.data.getAutonym( langCode ) || language || langCode,
|
||||
@@ -120,12 +120,13 @@
|
||||
$column.append( $li );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Get a column to add language.
|
||||
* @param regionCode string The region code
|
||||
* @param forceNew bool whether a new column must be created or not
|
||||
*/
|
||||
getColumn: function( regionCode, forceNew ) {
|
||||
getColumn: function ( regionCode, forceNew ) {
|
||||
var $divRegionCode, $rowDiv, $ul;
|
||||
|
||||
forceNew = forceNew || false;
|
||||
@@ -151,7 +152,7 @@
|
||||
return $ul;
|
||||
},
|
||||
|
||||
render: function() {
|
||||
render: function () {
|
||||
var $section, $sectionTitle,
|
||||
lcd = this,
|
||||
regions = {
|
||||
@@ -165,11 +166,13 @@
|
||||
PA: 'Pacific'
|
||||
};
|
||||
|
||||
$.each( $.uls.data.regiongroups, function( regionCode, regionIndex ) {
|
||||
$.each( $.uls.data.regiongroups, function ( regionCode, regionIndex ) {
|
||||
$section = $( '<div>' ).addClass( 'twelve columns uls-lcd-region-section' ).prop( 'id', regionCode );
|
||||
$sectionTitle = $( '<h3 data-i18n="uls-region-'+ regionCode+'">' )
|
||||
|
||||
$sectionTitle = $( '<h3 data-i18n="uls-region-' + regionCode + '">' )
|
||||
.addClass( 'eleven columns uls-lcd-region-section uls-lcd-region-title offset-by-one' )
|
||||
.text( regions[regionCode] );
|
||||
|
||||
$section.append( $sectionTitle );
|
||||
lcd.$element.append( $section );
|
||||
$section.hide();
|
||||
@@ -180,11 +183,11 @@
|
||||
this.i18n();
|
||||
},
|
||||
|
||||
i18n: function( ) {
|
||||
i18n: function ( ) {
|
||||
this.$element.find( '[data-i18n]' ).i18n();
|
||||
},
|
||||
|
||||
quicklist: function() {
|
||||
quicklist: function () {
|
||||
if ( $.isFunction( this.options.quickList ) ) {
|
||||
this.options.quickList = this.options.quickList();
|
||||
}
|
||||
@@ -197,6 +200,7 @@
|
||||
var quickList = this.options.quickList;
|
||||
quickList = quickList.slice( 0, 16 );
|
||||
quickList.sort( $.uls.data.sortByAutonym );
|
||||
|
||||
var $quickListSection = $( '<div>' ).addClass( 'twelve columns uls-lcd-region-section' ).prop( 'id', 'uls-lcd-quicklist' );
|
||||
var $quickListSectionTitle = $( '<h3 data-i18n="uls-common-languages">' )
|
||||
.addClass( 'eleven columns uls-lcd-region-section uls-lcd-region-title offset-by-one' )
|
||||
@@ -204,6 +208,7 @@
|
||||
$quickListSection.append( $quickListSectionTitle );
|
||||
this.$element.prepend( $quickListSection );
|
||||
this.regionDivs[ 'quick' ] = $quickListSection;
|
||||
|
||||
for ( var i = 0; i < quickList.length; i++) {
|
||||
var $column = this.getColumn( 'quick', i % 4 === 0 );
|
||||
var langCode = quickList[i];
|
||||
@@ -220,27 +225,29 @@
|
||||
);
|
||||
$column.append( $li );
|
||||
}
|
||||
|
||||
$quickListSection.show();
|
||||
$quickListSectionTitle.i18n();
|
||||
|
||||
return $quickListSection;
|
||||
},
|
||||
|
||||
show: function() {
|
||||
show: function () {
|
||||
if ( !this.regionDivs ) {
|
||||
this.render();
|
||||
}
|
||||
},
|
||||
|
||||
empty: function() {
|
||||
empty: function () {
|
||||
this.$element.find( 'div.uls-language-block' ).remove();
|
||||
this.$element.find( 'div.uls-lcd-region-section' ).hide();
|
||||
},
|
||||
|
||||
focus: function() {
|
||||
focus: function () {
|
||||
this.$element.focus();
|
||||
},
|
||||
|
||||
noResults: function() {
|
||||
noResults: function () {
|
||||
this.$noResults.show();
|
||||
var $suggestions = this.quicklist();
|
||||
$suggestions.find( 'h3' )
|
||||
@@ -254,7 +261,7 @@
|
||||
var lcd = this;
|
||||
|
||||
if ( this.options.clickhandler ) {
|
||||
this.$element.on( 'click', 'div.row li', function() {
|
||||
this.$element.on( 'click', 'div.row li', function () {
|
||||
lcd.options.clickhandler.call( this, $( this ).data( 'code' ) );
|
||||
} );
|
||||
}
|
||||
@@ -264,6 +271,7 @@
|
||||
var $ulsLanguageList = $( this ),
|
||||
scrollTop = $ulsLanguageList.position().top,
|
||||
scrollBottom = $ulsLanguageList.height();
|
||||
|
||||
if ( lcd.options.lazyload && lcd.options.source.val() === '' ) {
|
||||
if ( this.offsetHeight + this.scrollTop >= this.scrollHeight / 2 ) {
|
||||
lcd.$element.trigger( 'scrollend' );
|
||||
@@ -279,6 +287,7 @@
|
||||
|
||||
if ( top - padding <= scrollTop && height > scrollBottom ) {
|
||||
inviewRegion = $lcdRegionSection.attr( 'id' );
|
||||
|
||||
return true;
|
||||
}
|
||||
} );
|
||||
@@ -290,8 +299,8 @@
|
||||
}
|
||||
};
|
||||
|
||||
$.fn.lcd = function( option ) {
|
||||
return this.each( function() {
|
||||
$.fn.lcd = function ( option ) {
|
||||
return this.each( function () {
|
||||
var $this = $( this ),
|
||||
data = $this.data( 'lcd' ),
|
||||
options = typeof option === 'object' && option;
|
||||
@@ -299,6 +308,7 @@
|
||||
if ( !data ) {
|
||||
$this.data( 'lcd', ( data = new LanguageCategoryDisplay( this, options ) ) );
|
||||
}
|
||||
|
||||
if ( typeof option === 'string') {
|
||||
data[option]();
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
* The attached element should have data-regiongroup attribute
|
||||
* that defines the regiongroup for the selector.
|
||||
*/
|
||||
var RegionSelector = function( element, options ) {
|
||||
var RegionSelector = function ( element, options ) {
|
||||
this.$element = $( element );
|
||||
this.options = $.extend( {}, $.fn.regionselector.defaults, options );
|
||||
this.$element.addClass( 'regionselector' );
|
||||
@@ -42,32 +42,36 @@
|
||||
RegionSelector.prototype = {
|
||||
constructor: RegionSelector,
|
||||
|
||||
init: function() {
|
||||
init: function () {
|
||||
var region = this.$element.data( 'region' );
|
||||
this.regions = $.uls.data.getRegionsInGroup( this.regionGroup );
|
||||
|
||||
if ( region ) {
|
||||
this.regions.push( region );
|
||||
}
|
||||
},
|
||||
|
||||
test: function( langCode ) {
|
||||
test: function ( langCode ) {
|
||||
var langRegions = $.uls.data.getRegions( langCode ),
|
||||
region;
|
||||
|
||||
for ( var i = 0; i < this.regions.length; i++ ) {
|
||||
region = this.regions[i];
|
||||
|
||||
if ( $.inArray( region, langRegions ) >= 0 ) {
|
||||
this.render( langCode, region );
|
||||
this.cache[langCode] = region;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
show: function() {
|
||||
show: function () {
|
||||
if ( this.cache ) {
|
||||
// If the result cache is present, render the results from there.
|
||||
var result = null;
|
||||
|
||||
for ( result in this.cache ) {
|
||||
this.render( result, this.cache[result] );
|
||||
}
|
||||
@@ -75,11 +79,14 @@
|
||||
this.cache = {};
|
||||
// Get the languages grouped by script group
|
||||
var languagesByScriptGroup = $.uls.data.getLanguagesByScriptGroup( this.options.languages );
|
||||
|
||||
for ( var scriptGroup in languagesByScriptGroup ) {
|
||||
// Get the languages for the script group
|
||||
var languages = languagesByScriptGroup[scriptGroup];
|
||||
|
||||
// Sort it based on autonym
|
||||
languages.sort( $.uls.data.sortByAutonym );
|
||||
|
||||
for ( var i = 0; i < languages.length; i++ ) {
|
||||
// Check whether it belongs to the region
|
||||
this.test( languages[i] );
|
||||
@@ -92,11 +99,13 @@
|
||||
}
|
||||
},
|
||||
|
||||
render: function( langCode, region ) {
|
||||
render: function ( langCode, region ) {
|
||||
var $target = this.options.$target;
|
||||
|
||||
if ( !$target ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$target.append( langCode, region );
|
||||
},
|
||||
|
||||
@@ -113,21 +122,23 @@
|
||||
|
||||
var $nextRegion = $( '#uls-region-' + nextRegiongroup );
|
||||
var next = $nextRegion.length && $nextRegion.data( 'regionselector' );
|
||||
|
||||
if ( next ) {
|
||||
next.show();
|
||||
}
|
||||
}, 100 );
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
listen: function() {
|
||||
listen: function () {
|
||||
this.$element.on( 'click', $.proxy( this.click, this ) );
|
||||
this.options.$target.$element.bind( 'scrollend', $.proxy( this.next, this) );
|
||||
},
|
||||
|
||||
click: function( e ) {
|
||||
click: function ( e ) {
|
||||
// Don't do anything if a region is selected already
|
||||
if( this.$element.hasClass( 'active' ) ) {
|
||||
if ( this.$element.hasClass( 'active' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -136,6 +147,7 @@
|
||||
this.show();
|
||||
// Make the selected region (and it only) active
|
||||
$( '.regionselector' ).removeClass( 'active' );
|
||||
|
||||
if ( this.regionGroup ) {
|
||||
// if there is a region group, make it active.
|
||||
this.$element.addClass( 'active' );
|
||||
@@ -145,8 +157,8 @@
|
||||
|
||||
/* RegionSelector plugin definition */
|
||||
|
||||
$.fn.regionselector = function( option ) {
|
||||
return this.each( function() {
|
||||
$.fn.regionselector = function ( option ) {
|
||||
return this.each( function () {
|
||||
var $this = $( this ),
|
||||
data = $this.data( 'regionselector' ),
|
||||
options = typeof option === 'object' && option;
|
||||
@@ -154,6 +166,7 @@
|
||||
if ( !data ) {
|
||||
$this.data( 'regionselector', ( data = new RegionSelector( this, options ) ) );
|
||||
}
|
||||
|
||||
if ( typeof option === 'string' ) {
|
||||
data[option]();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user