diff --git a/lib/jquery.uls/src/jquery.uls.core.js b/lib/jquery.uls/src/jquery.uls.core.js index 31fc9677..edab8bc6 100644 --- a/lib/jquery.uls/src/jquery.uls.core.js +++ b/lib/jquery.uls/src/jquery.uls.core.js @@ -107,11 +107,7 @@ lcd = that.$resultsView.lcd( { languages: that.languages, - clickhandler: function( langCode ) { - if ( that.options.onSelect ) { - that.options.onSelect.call( this, langCode ); - } - } + clickhandler: $.proxy( that.onSelect, that ) } ).data( "lcd" ); that.$languageFilter.languagefilter( { @@ -119,7 +115,8 @@ languages: that.languages, success: $.proxy( that.success, that ), noresults: $.proxy( that.noresults, that ), - searchAPI: that.options.searchAPI + searchAPI: that.options.searchAPI, + onSelect: $.proxy( that.onSelect, that ) } ); // Create region selectors, one per region @@ -135,6 +132,12 @@ }, + onSelect: function( langCode ) { + if ( this.options.onSelect ) { + this.options.onSelect.call( this, langCode ); + } + }, + keyup: function( e ) { if ( !this.shown ) { return; diff --git a/lib/jquery.uls/src/jquery.uls.languagefilter.js b/lib/jquery.uls/src/jquery.uls.languagefilter.js index 42a12338..74c721b8 100644 --- a/lib/jquery.uls/src/jquery.uls.languagefilter.js +++ b/lib/jquery.uls/src/jquery.uls.languagefilter.js @@ -33,6 +33,7 @@ this.resultCount = 0; this.$suggestion = $( '#' + this.$element.data( 'suggestion' ) ); this.$clear = $( '#'+ this.$element.data( 'clear' ) ); + this.selectedLanguage = null; this.listen(); }; @@ -66,11 +67,16 @@ this.$element.val( suggestion ); e.preventDefault(); e.stopPropagation(); - } else { - this.options.$target.focus(); } + break; + case 13: + if ( this.options.onSelect && this.selectedLanguage ) { + this.options.onSelect( this.selectedLanguage ); + } + break; default: var that = this; + this.selectedLanguage = null; delay( function() { that.options.$target.empty(); that.search(); @@ -113,6 +119,9 @@ // Autofill the first result. this.autofill( langCode ); } + if ( query === langCode ) { + this.selectedLanguage = langCode; + } this.render( langCode ); this.resultCount++; } @@ -162,6 +171,7 @@ this.$suggestion.val( '' ); return; } + this.selectedLanguage = langCode; languageName = languageName || this.options.languages[langCode]; var autonym, userInput = this.$element.val(), @@ -229,7 +239,8 @@ searchAPI: null, languages: null, // Languages as code:name format. noresults: null, // callback for no results found case - success: null // callback if any results found. + success: null, // callback if any results found. + onSelect: null // Language select handler - like enter in filter textbox. }; $.fn.languagefilter.Constructor = LanguageFilter;