Use events instead of callbacks for success or no results

Allows extension users to bind for this event, also reduces callbacks

Change-Id: I14cc6d51ad23432956e3ea3275c72db26d71a8c8
This commit is contained in:
Santhosh Thottingal
2013-08-15 12:16:12 +05:30
parent d40c160cf6
commit 33ec9285e3
2 changed files with 11 additions and 17 deletions

View File

@@ -224,6 +224,7 @@
* Callback for no results found context.
*/
noresults: function () {
$( '.regionselector' ).removeClass( 'active' );
this.$resultsView.lcd( 'noResults' );
},
@@ -231,6 +232,7 @@
* callback for results found context.
*/
success: function () {
$( '.regionselector' ).removeClass( 'active' );
this.$resultsView.show();
},
@@ -244,7 +246,9 @@
// Register all event listeners to the ULS here.
uls.$element.on( 'click', $.proxy( uls.click, uls ) );
uls.$languageFilter.on( 'searchclear', $.proxy( uls.defaultSearch, uls ) );
uls.$languageFilter.on( 'searchclear.uls', $.proxy( uls.defaultSearch, uls ) );
uls.$languageFilter.on( 'noresults.uls', $.proxy( uls.noresults, uls ) );
uls.$languageFilter.on( 'resultsfound.uls', $.proxy( uls.success, uls ) );
// Close when clicking on the close button
uls.$menu.find( '#uls-close' ).on( 'click', $.proxy( uls.cancel, uls ) );
@@ -272,14 +276,6 @@
uls.$languageFilter.languagefilter( {
$target: lcd,
languages: uls.languages,
success: function () {
$( '.regionselector' ).removeClass( 'active' );
uls.success();
},
noresults: function () {
$( '.regionselector' ).removeClass( 'active' );
uls.noresults();
},
searchAPI: uls.options.searchAPI,
onSelect: $.proxy( uls.select, uls )
} );

View File

@@ -143,7 +143,7 @@
*/
clear: function() {
this.deactivate();
this.$element.trigger( 'searchclear' );
this.$element.trigger( 'searchclear.uls' );
},
/**
@@ -222,15 +222,15 @@
/**
* Handler method to be called once search is over.
* Based on search result call success or noresults callbacks
* Based on search result triggers resultsfound or noresults events
* @param query string
*/
resultHandler: function( query ) {
if ( this.resultCount === 0 && this.options.noresults ) {
if ( this.resultCount === 0 ) {
this.$suggestion.val( '' );
this.options.noresults.call( this, query );
} else if ( this.options.success ) {
this.options.success( this, query, this.resultCount );
this.$element.trigger( 'noresults.uls', query );
} else {
this.$element.trigger( 'resultsfound.uls', [query, this.resultCount] );
}
},
@@ -339,8 +339,6 @@
$target: null, // Where to append the results
searchAPI: null,
languages: null, // Languages as code:name format.
noresults: null, // callback for no results found case
success: null, // callback if any results found.
onSelect: null // Language select handler - like enter in filter textbox.
};