/** * Universal Language Selector * Language category display component - Used for showing the search results, * grouped by regions, scripts * * Copyright (C) 2012 Alolita Sharma, Amir Aharoni, Arun Ganesh, Brandon Harris, * Niklas Laxström, Pau Giner, Santhosh Thottingal, Siebrand Mazeland and other * contributors. See CREDITS for a list. * * UniversalLanguageSelector is dual licensed GPLv2 or later and MIT. You don't * have to do anything special to choose one license or the other and you don't * have to notify anyone which license you are using. You are free to use * UniversalLanguageSelector in commercial projects as long as the copyright * header is left intact. See files GPL-LICENSE and MIT-LICENSE for details. * * @file * @ingroup Extensions * @licence GNU General Public Licence 2.0 or later * @licence MIT License */ ( function ( $ ) { 'use strict'; var noResultsTemplate, LanguageCategoryDisplay; /*jshint multistr:true */ noResultsTemplate = '\
\

\ No results found\

\
\
\

\ You can search by language name, \ script name, ISO code of language or \ you can browse by region:\ America, \ Europe, \ Middle East, \ Africa, \ Asia, \ Pacific, \ Worldwide.\

\
\
\
'; /*jshint multistr:false */ 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.$noResults = this.$element.find( 'div.uls-no-results-view' ); this.render(); this.listen(); }; LanguageCategoryDisplay.prototype = { constructor: LanguageCategoryDisplay, append: function ( langCode, regionCode ) { this.addToRegion( langCode, regionCode ); this.$noResults.hide(); }, /** * Add the language to a region. * If the region parameter is given, add to that region alone * Otherwise to all regions that this language belongs. * @param langCode * @param region Optional region */ addToRegion: function ( langCode, region ) { var i, regionCode, $li, $column, lastLanguage, lastScriptGroup, currentScriptGroup, lcd = this, language = lcd.options.languages[langCode], langName = $.uls.data.getAutonym( langCode ) || language || langCode, regions = []; if ( region ) { regions.push( region ); } else { regions = $.uls.data.getRegions( langCode ); } // World wide languages need not be repeated in all regions. if ( $.inArray( 'WW', regions ) > -1 ) { regions = [ 'WW' ]; } for ( i = 0; i < regions.length; i++ ) { regionCode = regions[i]; $li = $( '
  • ' ) .data( 'code', langCode ) .attr( { lang: langCode, dir: $.uls.data.getDir( langCode ) } ) .append( $( '' ).prop( 'title', language ).html( langName ) ); // Append the element to the column in the list $column = lcd.getColumn( regionCode ); lastLanguage = $column.find( 'li:last' ).data( 'code' ); if ( lastLanguage ) { lastScriptGroup = $.uls.data.getScriptGroupOfLanguage( lastLanguage ); currentScriptGroup = $.uls.data.getScriptGroupOfLanguage( langCode ); if ( lastScriptGroup !== currentScriptGroup ) { if ( $column.find( 'li' ).length > 2 ) { // If column already has 2 or more languages, add a new column $column = lcd.getColumn( regionCode, true ); } } } $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 ) { var $divRegionCode, $rowDiv, $ul; forceNew = forceNew || false; $divRegionCode = this.regionDivs[regionCode]; $rowDiv = $divRegionCode.find( 'div.row:last' ); $ul = $rowDiv.find( 'ul:last' ); // Each column can have maximum 8 languages. if ( $ul.length === 0 || $ul.find( 'li' ).length >= 8 || forceNew ) { $ul = $( '