Fix issue #31 - Add onCancel callback

Change-Id: I207b60846a899912dcc5f79f92e9b1ad75e525a3
This commit is contained in:
Santhosh Thottingal
2012-11-10 17:52:44 +05:30
parent 642dd3c8cc
commit cff31e7abb

View File

@@ -210,7 +210,7 @@
that.$languageFilter.on( 'seachclear', $.proxy( that.defaultSearch, that ) ); that.$languageFilter.on( 'seachclear', $.proxy( that.defaultSearch, that ) );
// Handle click on close button // Handle click on close button
this.$menu.find( "#uls-close" ).on( 'click', $.proxy( that.hide, that ) ); this.$menu.find( "#uls-close" ).on( 'click', $.proxy( that.cancel, that ) );
// Handle key press events on the menu // Handle key press events on the menu
that.$menu.on('keypress', $.proxy(this.keypress, this) ) that.$menu.on('keypress', $.proxy(this.keypress, this) )
@@ -222,7 +222,7 @@
lcd = that.$resultsView.lcd( { lcd = that.$resultsView.lcd( {
languages: that.languages, languages: that.languages,
quickList: that.options.quickList, quickList: that.options.quickList,
clickhandler: $.proxy( that.onSelect, that ), clickhandler: $.proxy( that.select, that ),
lazyload: that.options.lazyload, lazyload: that.options.lazyload,
source: that.$languageFilter source: that.$languageFilter
} ).data( "lcd" ); } ).data( "lcd" );
@@ -239,7 +239,7 @@
that.noresults(); that.noresults();
}, },
searchAPI: that.options.searchAPI, searchAPI: that.options.searchAPI,
onSelect: $.proxy( that.onSelect, that ) onSelect: $.proxy( that.select, that )
} ); } );
// Create region selectors, one per region // Create region selectors, one per region
@@ -266,19 +266,29 @@
* On select handler for search results * On select handler for search results
* @param langCode * @param langCode
*/ */
onSelect: function( langCode ) { select: function( langCode ) {
this.hide(); this.hide();
if ( this.options.onSelect ) { if ( this.options.onSelect ) {
this.options.onSelect.call( this, langCode ); this.options.onSelect.call( this, langCode );
} }
}, },
/**
* On cancel handler for the uls menu
*/
cancel: function() {
this.hide();
if ( this.options.onCancel ) {
this.options.onCancel.call( this );
}
},
keyup: function( e ) { keyup: function( e ) {
if ( !this.shown ) { if ( !this.shown ) {
return; return;
} }
if ( e.keyCode === 27 ) { // escape if ( e.keyCode === 27 ) { // escape
this.hide(); this.cancel();
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
} }
@@ -289,7 +299,7 @@
return; return;
} }
if ( e.keyCode === 27 ) { // escape if ( e.keyCode === 27 ) { // escape
this.hide(); this.cancel();
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
} }