From ee7f16526c12d794cd20a5d060f0b713e703bacf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Laxstr=C3=B6m?= Date: Thu, 16 Aug 2012 09:31:48 +0000 Subject: [PATCH] (bug 39230) Autocompletion does not get cleared on region change * Introduced deactivate (clear without showing all languages) * Renamed noresult in region filter to noresults to match the callback in languagefilter * Some comments to help understand the code Change-Id: I544a29b860a6d3f4a5aa770f84cc8a72ae4a4b9d --- lib/jquery.uls/src/jquery.uls.core.js | 7 +++--- .../src/jquery.uls.languagefilter.js | 24 +++++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/jquery.uls/src/jquery.uls.core.js b/lib/jquery.uls/src/jquery.uls.core.js index eea8a8f9..5d3472a7 100644 --- a/lib/jquery.uls/src/jquery.uls.core.js +++ b/lib/jquery.uls/src/jquery.uls.core.js @@ -159,11 +159,12 @@ $target: lcd, languages: that.languages, success: function() { - // clear the search field. - that.$languageFilter.val( '' ); + // Deactivate search filtering + that.$languageFilter.languagefilter( 'deactivate' ); + // Show 'results view' if we are in no results mode that.success(); }, - noresult: function() { + noresults: function() { that.$languageFilter.languagefilter( 'clear' ); } } ); diff --git a/lib/jquery.uls/src/jquery.uls.languagefilter.js b/lib/jquery.uls/src/jquery.uls.languagefilter.js index 6e7d8d90..30cfeff9 100644 --- a/lib/jquery.uls/src/jquery.uls.languagefilter.js +++ b/lib/jquery.uls/src/jquery.uls.languagefilter.js @@ -85,13 +85,29 @@ } }, - clear: function() { + /** + * Clears the current search removing + * clear buttons and suggestions. + */ + deactivate: function() { this.$element.val( '' ); this.$element.focus(); this.toggleClear(); + this.autofill(); + }, + + /** + * Clears the search and shows all languages + */ + clear: function() { + this.deactivate(); this.search(); }, + /** + * Toggles the visibility of clear icon depending + * on whether there is anything to clear. + */ toggleClear: function() { if ( !this.$clear.length ) { return; @@ -331,8 +347,8 @@ click: function( e ) { if( this.$element.hasClass( 'active' ) ) { this.$element.removeClass( 'active' ); - if ( this.options.noresult ) { - this.options.noresult.call(); + if ( this.options.noresults ) { + this.options.noresults.call(); } } else { this.show(); @@ -360,7 +376,7 @@ $.fn.regionselector.defaults = { $target: null, // Where to render the results success: null, // callback if any results found. - noresult: null, // callback when no results to show + noresults: null, // callback when no results to show languages: null };