Update jquery.uls to ab3cd92
Important changes: * Remove region filter module * Remove jquery.uls.compact.css * Remove unused methods from jquery.uls.data.utils module * Localisation updates Change-Id: If87bd21e19780fa5d90cedb4235854816c4adfba
This commit is contained in:
committed by
Niklas Laxström
parent
384b109362
commit
f3b984e4e1
@@ -189,6 +189,10 @@
|
||||
hide: function () {
|
||||
this.$menu.hide();
|
||||
this.shown = false;
|
||||
|
||||
if ( this.options.onCancel ) {
|
||||
this.options.onCancel.call( this );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -217,8 +221,7 @@
|
||||
* Bind the UI elements with their event listeners
|
||||
*/
|
||||
listen: function () {
|
||||
var lcd, columnsOptions, languagesCount,
|
||||
uls = this;
|
||||
var lcd, columnsOptions, languagesCount;
|
||||
|
||||
columnsOptions = {
|
||||
wide: 4,
|
||||
@@ -261,28 +264,6 @@
|
||||
onSelect: $.proxy( this.select, this )
|
||||
} );
|
||||
|
||||
// Create region selectors, one per region
|
||||
this.regionFilter = new $.uls.RegionSelector( {
|
||||
$target: lcd,
|
||||
languages: this.languages,
|
||||
success: function ( regionfilter ) {
|
||||
// Deactivate search filtering
|
||||
uls.$languageFilter.languagefilter( 'deactivate' );
|
||||
|
||||
// If it is the WW region, show the quicklist
|
||||
if ( regionfilter.regionGroup === 1 ) {
|
||||
lcd.quicklist();
|
||||
}
|
||||
|
||||
// Show 'results view' if we are in no results mode
|
||||
uls.success();
|
||||
},
|
||||
noresults: function () {
|
||||
uls.$languageFilter.languagefilter( 'clear' );
|
||||
}
|
||||
} );
|
||||
|
||||
this.$languageFilter.on( 'searchclear.uls', $.proxy( this.regionFilter.show, this.regionFilter ) );
|
||||
this.$languageFilter.on( 'noresults.uls', $.proxy( this.noresults, this ) );
|
||||
this.$languageFilter.on( 'resultsfound.uls', $.proxy( this.success, this ) );
|
||||
|
||||
@@ -295,7 +276,6 @@
|
||||
*/
|
||||
select: function ( langCode ) {
|
||||
this.hide();
|
||||
this.$languageFilter.trigger( 'searchclear' );
|
||||
if ( this.options.onSelect ) {
|
||||
this.options.onSelect.call( this, langCode );
|
||||
}
|
||||
@@ -310,10 +290,6 @@
|
||||
}
|
||||
|
||||
this.hide();
|
||||
|
||||
if ( this.options.onCancel ) {
|
||||
this.options.onCancel.call( this );
|
||||
}
|
||||
},
|
||||
|
||||
keyup: function ( e ) {
|
||||
|
||||
@@ -99,21 +99,6 @@
|
||||
return autonymsByCode;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an array of all region codes.
|
||||
* @return array
|
||||
*/
|
||||
$.uls.data.getAllRegions = function () {
|
||||
var region,
|
||||
allRegions = [];
|
||||
|
||||
for ( region in $.uls.data.regiongroups ) {
|
||||
allRegions.push( region );
|
||||
}
|
||||
|
||||
return allRegions;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns all languages written in script.
|
||||
* @param script string
|
||||
@@ -148,77 +133,6 @@
|
||||
return languagesInScripts;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns all languages in a given region.
|
||||
* @param region string
|
||||
* @return array of strings (languages codes)
|
||||
*/
|
||||
$.uls.data.getLanguagesInRegion = function ( region ) {
|
||||
return $.uls.data.getLanguagesInRegions( [ region ] );
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns all languages in given regions.
|
||||
* @param regions array of strings.
|
||||
* @return array of strings (languages codes)
|
||||
*/
|
||||
$.uls.data.getLanguagesInRegions = function ( regions ) {
|
||||
var language, i,
|
||||
languagesInRegions = [];
|
||||
|
||||
for ( language in $.uls.data.languages ) {
|
||||
if ( $.uls.data.isRedirect( language ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for ( i = 0; i < regions.length; i++ ) {
|
||||
if ( $.inArray( regions[i], $.uls.data.getRegions( language ) ) !== -1 ) {
|
||||
languagesInRegions.push( language );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return languagesInRegions;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns all languages in a region group.
|
||||
* @param groupNum number.
|
||||
* @return array of strings (languages codes)
|
||||
*/
|
||||
$.uls.data.getLanguagesInRegionGroup = function ( groupNum ) {
|
||||
return $.uls.data.getLanguagesInRegions( $.uls.data.getRegionsInGroup( groupNum ) );
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an associative array of languages in a region,
|
||||
* grouped by script.
|
||||
* @param region string Region code
|
||||
* @return associative array
|
||||
*/
|
||||
$.uls.data.getLanguagesByScriptInRegion = function ( region ) {
|
||||
var language, script,
|
||||
languagesByScriptInRegion = {};
|
||||
|
||||
for ( language in $.uls.data.languages ) {
|
||||
if ( $.uls.data.isRedirect( language ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $.inArray( region, $.uls.data.getRegions( language ) ) !== -1 ) {
|
||||
script = $.uls.data.getScript( language );
|
||||
|
||||
if ( languagesByScriptInRegion[script] === undefined ) {
|
||||
languagesByScriptInRegion[script] = [];
|
||||
}
|
||||
languagesByScriptInRegion[script].push( language );
|
||||
}
|
||||
}
|
||||
|
||||
return languagesByScriptInRegion;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an associative array of languages in a region,
|
||||
* grouped by script group.
|
||||
@@ -229,15 +143,6 @@
|
||||
return $.uls.data.getLanguagesByScriptGroupInRegions( [ region ] );
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an associative array of all languages,
|
||||
* grouped by script group.
|
||||
* @return associative array
|
||||
*/
|
||||
$.uls.data.getAllLanguagesByScriptGroup = function () {
|
||||
return $.uls.data.getLanguagesByScriptGroupInRegions( $.uls.data.getAllRegions() );
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the given list of languages grouped by script.
|
||||
* @param languages Array of language codes
|
||||
@@ -294,72 +199,6 @@
|
||||
return languagesByScriptGroupInRegions;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an array of languages grouped by region group,
|
||||
* region, script group and script.
|
||||
* @return associative array
|
||||
*/
|
||||
$.uls.data.getAllLanguagesByRegionAndScript = function () {
|
||||
var region, regionGroup, language,
|
||||
script, scriptGroup, regions, regionNum,
|
||||
allLanguagesByRegionAndScript = {};
|
||||
|
||||
for ( region in $.uls.data.regiongroups ) {
|
||||
regionGroup = $.uls.data.regiongroups[region];
|
||||
|
||||
if ( allLanguagesByRegionAndScript[regionGroup] === undefined ) {
|
||||
allLanguagesByRegionAndScript[regionGroup] = {};
|
||||
}
|
||||
|
||||
allLanguagesByRegionAndScript[regionGroup][region] = {};
|
||||
}
|
||||
|
||||
for ( language in $.uls.data.languages ) {
|
||||
if ( $.uls.data.isRedirect( language ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
script = $.uls.data.getScript( language );
|
||||
scriptGroup = $.uls.data.getGroupOfScript( script );
|
||||
regions = $.uls.data.getRegions( language );
|
||||
|
||||
for ( regionNum = 0; regionNum < regions.length; regionNum++ ) {
|
||||
region = regions[regionNum];
|
||||
regionGroup = $.uls.data.regiongroups[region];
|
||||
|
||||
if ( allLanguagesByRegionAndScript[regionGroup][region][scriptGroup] === undefined ) {
|
||||
allLanguagesByRegionAndScript[regionGroup][region][scriptGroup] = {};
|
||||
}
|
||||
|
||||
if ( allLanguagesByRegionAndScript[regionGroup][region][scriptGroup][script] === undefined ) {
|
||||
allLanguagesByRegionAndScript[regionGroup][region][scriptGroup][script] = [];
|
||||
}
|
||||
|
||||
allLanguagesByRegionAndScript[regionGroup][region][scriptGroup][script].push( language );
|
||||
}
|
||||
}
|
||||
|
||||
return allLanguagesByRegionAndScript;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns all regions in a region group.
|
||||
* @param groupNum int
|
||||
* @return array of strings
|
||||
*/
|
||||
$.uls.data.getRegionsInGroup = function ( groupNum ) {
|
||||
var region,
|
||||
regionsInGroup = [];
|
||||
|
||||
for ( region in $.uls.data.regiongroups ) {
|
||||
if ( $.uls.data.regiongroups[region] === groupNum ) {
|
||||
regionsInGroup.push( region );
|
||||
}
|
||||
}
|
||||
|
||||
return regionsInGroup;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the script group of a script or 'Other' if it doesn't
|
||||
* belong to any group.
|
||||
|
||||
@@ -22,12 +22,12 @@
|
||||
* The values for autocompletion is from the options.languages.
|
||||
* The data is in the format of languagecode:languagename.
|
||||
*/
|
||||
(function ( $ ) {
|
||||
( function ( $ ) {
|
||||
'use strict';
|
||||
|
||||
var LanguageFilter, delay;
|
||||
|
||||
LanguageFilter = function( element, options ) {
|
||||
LanguageFilter = function ( element, options ) {
|
||||
this.$element = $( element );
|
||||
this.options = $.extend( {}, $.fn.languagefilter.defaults, options );
|
||||
this.$element.addClass( 'languagefilter' );
|
||||
@@ -35,21 +35,25 @@
|
||||
this.$suggestion = this.$element.parents().find( '#' + this.$element.data( 'suggestion' ) );
|
||||
this.$clear = this.$element.parents().find( '#' + this.$element.data( 'clear' ) );
|
||||
this.selectedLanguage = null;
|
||||
|
||||
this.init();
|
||||
this.listen();
|
||||
};
|
||||
|
||||
delay = ( function() {
|
||||
delay = ( function () {
|
||||
var timer = 0;
|
||||
|
||||
return function( callback, milliseconds ) {
|
||||
return function ( callback, milliseconds ) {
|
||||
clearTimeout( timer );
|
||||
timer = setTimeout( callback, milliseconds );
|
||||
};
|
||||
} () );
|
||||
}() );
|
||||
|
||||
LanguageFilter.prototype = {
|
||||
listen: function() {
|
||||
init: function () {
|
||||
this.search();
|
||||
},
|
||||
|
||||
listen: function () {
|
||||
this.$element.on( 'keypress', $.proxy( this.keyup, this ) )
|
||||
.on( 'keyup', $.proxy( this.keyup, this ) );
|
||||
|
||||
@@ -58,68 +62,68 @@
|
||||
}
|
||||
|
||||
if ( this.$clear.length ) {
|
||||
this.$clear.on( 'click' , $.proxy( this.clear, this ) );
|
||||
this.$clear.on( 'click', $.proxy( this.clear, this ) );
|
||||
}
|
||||
|
||||
this.toggleClear();
|
||||
},
|
||||
|
||||
keyup: function( e ) {
|
||||
keyup: function ( e ) {
|
||||
var suggestion, query, languageFilter;
|
||||
|
||||
switch( e.keyCode ) {
|
||||
case 9: // Tab -> Autocomplete
|
||||
suggestion = this.$suggestion.val();
|
||||
switch ( e.keyCode ) {
|
||||
case 9: // Tab -> Autocomplete
|
||||
suggestion = this.$suggestion.val();
|
||||
|
||||
if ( suggestion && suggestion !== this.$element.val() ) {
|
||||
this.$element.val( suggestion );
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}
|
||||
break;
|
||||
case 13: // Enter
|
||||
if ( !this.options.onSelect ) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Avoid bubbling this 'enter' to background page elements
|
||||
if ( suggestion && suggestion !== this.$element.val() ) {
|
||||
this.$element.val( suggestion );
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
query = $.trim( this.$element.val() ).toLowerCase();
|
||||
|
||||
if ( this.selectedLanguage ) {
|
||||
// this.selectLanguage will be populated from a matching search
|
||||
this.options.onSelect( this.selectedLanguage );
|
||||
} else if ( this.options.languages[query] ) {
|
||||
// Search is yet to happen (in timeout delay),
|
||||
// but we have a matching language code.
|
||||
this.options.onSelect( query );
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case 13: // Enter
|
||||
if ( !this.options.onSelect ) {
|
||||
break;
|
||||
default:
|
||||
languageFilter = this;
|
||||
}
|
||||
|
||||
if ( e.which < 32 &&
|
||||
e.which !== 8 // Backspace
|
||||
) {
|
||||
// ignore any ASCII control characters
|
||||
break;
|
||||
// Avoid bubbling this 'enter' to background page elements
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
query = $.trim( this.$element.val() ).toLowerCase();
|
||||
|
||||
if ( this.selectedLanguage ) {
|
||||
// this.selectLanguage will be populated from a matching search
|
||||
this.options.onSelect( this.selectedLanguage );
|
||||
} else if ( this.options.languages[ query ] ) {
|
||||
// Search is yet to happen (in timeout delay),
|
||||
// but we have a matching language code.
|
||||
this.options.onSelect( query );
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
languageFilter = this;
|
||||
|
||||
if ( e.which < 32 &&
|
||||
e.which !== 8 // Backspace
|
||||
) {
|
||||
// ignore any ASCII control characters
|
||||
break;
|
||||
}
|
||||
|
||||
this.selectedLanguage = null;
|
||||
|
||||
delay( function () {
|
||||
if ( !languageFilter.$element.val() ) {
|
||||
languageFilter.clear();
|
||||
} else {
|
||||
languageFilter.options.$target.empty();
|
||||
languageFilter.search();
|
||||
}
|
||||
}, 300 );
|
||||
|
||||
this.selectedLanguage = null;
|
||||
|
||||
delay( function() {
|
||||
if ( !languageFilter.$element.val() ) {
|
||||
languageFilter.clear();
|
||||
} else {
|
||||
languageFilter.options.$target.empty();
|
||||
languageFilter.search();
|
||||
}
|
||||
}, 300 );
|
||||
|
||||
this.toggleClear();
|
||||
this.toggleClear();
|
||||
}
|
||||
},
|
||||
|
||||
@@ -127,7 +131,7 @@
|
||||
* Clears the current search removing
|
||||
* clear buttons and suggestions.
|
||||
*/
|
||||
deactivate: function() {
|
||||
deactivate: function () {
|
||||
this.$element.val( '' );
|
||||
|
||||
if ( !$.fn.uls.Constructor.prototype.isMobile() ) {
|
||||
@@ -141,16 +145,16 @@
|
||||
/**
|
||||
* Clears the search and shows all languages
|
||||
*/
|
||||
clear: function() {
|
||||
clear: function () {
|
||||
this.deactivate();
|
||||
this.$element.trigger( 'searchclear.uls' );
|
||||
this.search();
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggles the visibility of clear icon depending
|
||||
* on whether there is anything to clear.
|
||||
*/
|
||||
toggleClear: function() {
|
||||
toggleClear: function () {
|
||||
if ( !this.$clear.length ) {
|
||||
return;
|
||||
}
|
||||
@@ -163,41 +167,48 @@
|
||||
},
|
||||
|
||||
search: function () {
|
||||
var langCode,
|
||||
var langCode, scriptGroup, langNum, languagesInScript,
|
||||
languages = $.uls.data.getLanguagesByScriptGroup( this.options.languages ),
|
||||
query = $.trim( this.$element.val() );
|
||||
|
||||
this.resultCount = 0;
|
||||
for ( scriptGroup in languages ) {
|
||||
languagesInScript = languages[ scriptGroup ];
|
||||
languagesInScript.sort( $.uls.data.sortByAutonym );
|
||||
for ( langNum = 0; langNum < languagesInScript.length; langNum++ ) {
|
||||
langCode = languagesInScript[ langNum ];
|
||||
if ( query === '' || this.filter( langCode, query ) ) {
|
||||
if ( this.resultCount === 0 ) {
|
||||
// Autofill the first result.
|
||||
this.autofill( langCode );
|
||||
}
|
||||
|
||||
for ( langCode in this.options.languages ) {
|
||||
if ( query === '' || this.filter( langCode, query ) ) {
|
||||
if ( this.resultCount === 0 ) {
|
||||
// Autofill the first result.
|
||||
this.autofill( langCode );
|
||||
}
|
||||
if ( query.toLowerCase() === langCode ) {
|
||||
this.selectedLanguage = langCode;
|
||||
}
|
||||
|
||||
if ( query.toLowerCase() === langCode ) {
|
||||
this.selectedLanguage = langCode;
|
||||
}
|
||||
|
||||
if ( this.render( langCode ) ) {
|
||||
this.resultCount++;
|
||||
if ( this.render( langCode ) ) {
|
||||
this.resultCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Also do a search by search API
|
||||
if( !this.resultCount && this.options.searchAPI && query ) {
|
||||
if ( !this.resultCount && this.options.searchAPI && query ) {
|
||||
this.searchAPI( query );
|
||||
} else {
|
||||
this.resultHandler( query );
|
||||
}
|
||||
},
|
||||
|
||||
searchAPI: function( query ) {
|
||||
searchAPI: function ( query ) {
|
||||
var languageFilter = this;
|
||||
|
||||
$.get( languageFilter.options.searchAPI, { search: query }, function( result ) {
|
||||
$.each( result.languagesearch, function( code, name ) {
|
||||
$.get( languageFilter.options.searchAPI, {
|
||||
search: query
|
||||
}, function ( result ) {
|
||||
$.each( result.languagesearch, function ( code, name ) {
|
||||
if ( languageFilter.resultCount === 0 ) {
|
||||
// Autofill the first result.
|
||||
languageFilter.autofill( code, name );
|
||||
@@ -219,16 +230,18 @@
|
||||
* Based on search result triggers resultsfound or noresults events
|
||||
* @param query string
|
||||
*/
|
||||
resultHandler: function( query ) {
|
||||
resultHandler: function ( query ) {
|
||||
if ( this.resultCount === 0 ) {
|
||||
this.$suggestion.val( '' );
|
||||
this.$element.trigger( 'noresults.uls', query );
|
||||
} else {
|
||||
this.$element.trigger( 'resultsfound.uls', [query, this.resultCount] );
|
||||
this.$element.trigger( 'resultsfound.uls', [ query, this.resultCount ] );
|
||||
}
|
||||
},
|
||||
|
||||
autofill: function( langCode, languageName ) {
|
||||
autofill: function ( langCode, languageName ) {
|
||||
var autonym, userInput, suggestion;
|
||||
|
||||
if ( !this.$suggestion.length ) {
|
||||
return;
|
||||
}
|
||||
@@ -239,15 +252,14 @@
|
||||
}
|
||||
|
||||
this.selectedLanguage = langCode;
|
||||
languageName = languageName || this.options.languages[langCode];
|
||||
languageName = languageName || this.options.languages[ langCode ];
|
||||
|
||||
if ( !languageName ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var autonym,
|
||||
userInput = this.$element.val(),
|
||||
suggestion = userInput + languageName.substring( userInput.length, languageName.length );
|
||||
userInput = this.$element.val();
|
||||
suggestion = userInput + languageName.substring( userInput.length, languageName.length );
|
||||
|
||||
if ( suggestion.toLowerCase() !== languageName.toLowerCase() ) {
|
||||
// see if it was autonym match
|
||||
@@ -268,7 +280,7 @@
|
||||
this.$suggestion.val( suggestion );
|
||||
},
|
||||
|
||||
render: function( langCode ) {
|
||||
render: function ( langCode ) {
|
||||
var $target = this.options.$target;
|
||||
|
||||
if ( !$target ) {
|
||||
@@ -278,7 +290,7 @@
|
||||
return $target.append( langCode );
|
||||
},
|
||||
|
||||
escapeRegex: function( value ) {
|
||||
escapeRegex: function ( value ) {
|
||||
return value.replace( /[\-\[\]{}()*+?.,\\\^$\|#\s]/g, '\\$&' );
|
||||
},
|
||||
|
||||
@@ -290,10 +302,10 @@
|
||||
* c) ISO 639 code match with search string.
|
||||
* d) ISO 15924 code for the script match the search string.
|
||||
*/
|
||||
filter: function( langCode, searchTerm ) {
|
||||
filter: function ( langCode, searchTerm ) {
|
||||
// FIXME script is ISO 15924 code. We might need actual name of script.
|
||||
var matcher = new RegExp( '^' + this.escapeRegex( searchTerm ), 'i' ),
|
||||
languageName = this.options.languages[langCode];
|
||||
languageName = this.options.languages[ langCode ];
|
||||
|
||||
return matcher.test( languageName ) ||
|
||||
matcher.test( $.uls.data.getAutonym( langCode ) ) ||
|
||||
@@ -306,15 +318,15 @@
|
||||
|
||||
if ( !isSupported ) {
|
||||
this.$element.setAttribute( eventName, 'return;' );
|
||||
isSupported = typeof this.$element[eventName] === 'function';
|
||||
isSupported = typeof this.$element[ eventName ] === 'function';
|
||||
}
|
||||
|
||||
return isSupported;
|
||||
}
|
||||
};
|
||||
|
||||
$.fn.languagefilter = function( option ) {
|
||||
return this.each( function() {
|
||||
$.fn.languagefilter = function ( option ) {
|
||||
return this.each( function () {
|
||||
var $this = $( this ),
|
||||
data = $this.data( 'languagefilter' ),
|
||||
options = typeof option === 'object' && option;
|
||||
@@ -324,7 +336,7 @@
|
||||
}
|
||||
|
||||
if ( typeof option === 'string' ) {
|
||||
data[option]();
|
||||
data[ option ]();
|
||||
}
|
||||
} );
|
||||
};
|
||||
@@ -340,13 +352,14 @@
|
||||
|
||||
/**
|
||||
* Check if a prefix is visually prefix of a string
|
||||
* @param prefix string
|
||||
* @param string string
|
||||
*
|
||||
* @param {string} prefix
|
||||
* @param {string} string
|
||||
*/
|
||||
function isVisualPrefix( prefix, string ) {
|
||||
// Pre-base vowel signs of Indic languages. A vowel sign is called pre-base if
|
||||
// consonant + vowel becomes [vowel][consonant] when rendered. Eg: ക + െ => കെ
|
||||
var prebases = 'െേൈൊോൌெேைொோௌେୈୋୌિਿिিেৈোৌෙේෛොෝෞ';
|
||||
return prebases.indexOf( string[prefix.length] ) <= 0;
|
||||
return prebases.indexOf( string[ prefix.length ] ) <= 0;
|
||||
}
|
||||
} ( jQuery ) );
|
||||
}( jQuery ) );
|
||||
|
||||
@@ -368,7 +368,7 @@
|
||||
.data( 'i18n', 'uls-no-results-suggestion-title' )
|
||||
.text( 'You may be interested in:' )
|
||||
.i18n();
|
||||
this.$noResults.find( 'h2' ).after( $suggestions );
|
||||
this.$noResults.find( 'h2' ).after( $suggestions.show() );
|
||||
},
|
||||
|
||||
listen: function () {
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
/**
|
||||
* Region Filter for ULS
|
||||
*
|
||||
* 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';
|
||||
|
||||
/**
|
||||
* Region selector is a language selector based on regions.
|
||||
* that defines the regiongroup for the selector.
|
||||
*/
|
||||
var RegionSelector = function ( options ) {
|
||||
this.options = options;
|
||||
this.regions = [];
|
||||
this.cache = null;
|
||||
this.init();
|
||||
};
|
||||
|
||||
RegionSelector.prototype = {
|
||||
constructor: RegionSelector,
|
||||
|
||||
init: function () {
|
||||
this.regions = this.options.regions || $.uls.data.getAllRegions();
|
||||
this.show();
|
||||
},
|
||||
|
||||
test: function ( langCode ) {
|
||||
var region, i,
|
||||
langRegions = $.uls.data.getRegions( langCode );
|
||||
|
||||
for ( 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 () {
|
||||
var result, languagesByScriptGroup, scriptGroup, languages, i,
|
||||
$target = this.options.$target && this.options.$target.$target,
|
||||
$parent = $target && $target.parent(),
|
||||
$prev = $target && $target.prev();
|
||||
|
||||
if ( $target && $parent ) {
|
||||
// Avoid reflows while adding new elements to the list
|
||||
// Use .detach() to keep jQuery events and data associated with elements
|
||||
$target.detach();
|
||||
}
|
||||
|
||||
if ( this.cache ) {
|
||||
// If the result cache is present, render the results from there.
|
||||
//noinspection JSUnusedAssignment
|
||||
result = null;
|
||||
|
||||
for ( result in this.cache ) {
|
||||
this.render( result, this.cache[ result ] );
|
||||
}
|
||||
} else {
|
||||
this.cache = {};
|
||||
// Get the languages grouped by script group
|
||||
languagesByScriptGroup = $.uls.data.getLanguagesByScriptGroup( this.options.languages );
|
||||
|
||||
// Make sure that we go by the original order
|
||||
// of script groups
|
||||
for ( scriptGroup in $.uls.data.scriptgroups ) {
|
||||
// Get the languages for the script group
|
||||
languages = languagesByScriptGroup[ scriptGroup ];
|
||||
|
||||
// It's possible that some script groups are missing
|
||||
if ( !languages ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Sort it based on autonym
|
||||
languages.sort( $.uls.data.sortByAutonym );
|
||||
|
||||
for ( i = 0; i < languages.length; i++ ) {
|
||||
// Check whether it belongs to the region
|
||||
this.test( languages[ i ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $target && $parent ) {
|
||||
// Restore the element to where we removed it from
|
||||
if ( $prev ) {
|
||||
$prev.after( $target );
|
||||
} else {
|
||||
$parent.append( $target );
|
||||
}
|
||||
}
|
||||
|
||||
if ( this.options.success ) {
|
||||
this.options.success( this );
|
||||
}
|
||||
},
|
||||
|
||||
render: function ( langCode, region ) {
|
||||
var $target = this.options.$target;
|
||||
|
||||
if ( !$target ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$target.append( langCode, region );
|
||||
},
|
||||
};
|
||||
|
||||
$.uls.RegionSelector = RegionSelector;
|
||||
}( jQuery ) );
|
||||
Reference in New Issue
Block a user