Simplify key press event handlers
Remove eventSupported checks and just rely on jquery.keydown
This commit is contained in:
@@ -225,12 +225,7 @@
|
|||||||
} );
|
} );
|
||||||
|
|
||||||
// Handle key press events on the menu
|
// Handle key press events on the menu
|
||||||
this.$menu.on( 'keypress', $.proxy( this.keypress, this ) )
|
this.$menu.keydown( $.proxy( this.keypress, this ) );
|
||||||
.on( 'keyup', $.proxy( this.keyup, this ) );
|
|
||||||
|
|
||||||
if ( this.eventSupported( 'keydown' ) ) {
|
|
||||||
this.$menu.on( 'keydown', $.proxy( this.keypress, this ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
languagesCount = Object.keys( this.options.languages ).length;
|
languagesCount = Object.keys( this.options.languages ).length;
|
||||||
lcd = this.$resultsView.lcd( {
|
lcd = this.$resultsView.lcd( {
|
||||||
@@ -280,18 +275,6 @@
|
|||||||
this.hide();
|
this.hide();
|
||||||
},
|
},
|
||||||
|
|
||||||
keyup: function ( e ) {
|
|
||||||
if ( !this.shown ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( e.keyCode === 27 ) { // escape
|
|
||||||
this.cancel();
|
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
keypress: function ( e ) {
|
keypress: function ( e ) {
|
||||||
if ( !this.shown ) {
|
if ( !this.shown ) {
|
||||||
return;
|
return;
|
||||||
@@ -312,17 +295,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
eventSupported: function ( eventName ) {
|
|
||||||
var isSupported = eventName in this.$menu;
|
|
||||||
|
|
||||||
if ( !isSupported ) {
|
|
||||||
this.$element.setAttribute( eventName, 'return;' );
|
|
||||||
isSupported = typeof this.$element[ eventName ] === 'function';
|
|
||||||
}
|
|
||||||
|
|
||||||
return isSupported;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the panel menu width parameter
|
* Get the panel menu width parameter
|
||||||
* @return {string}
|
* @return {string}
|
||||||
|
|||||||
@@ -68,12 +68,8 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
listen: function () {
|
listen: function () {
|
||||||
this.$element.on( 'keypress', $.proxy( this.keyup, this ) )
|
|
||||||
.on( 'keyup', $.proxy( this.keyup, this ) );
|
|
||||||
|
|
||||||
if ( this.eventSupported( 'keydown' ) ) {
|
this.$element.keydown( $.proxy( this.keypress, this ) );
|
||||||
this.$element.on( 'keydown', $.proxy( this.keyup, this ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( this.$clear.length ) {
|
if ( this.$clear.length ) {
|
||||||
this.$clear.on( 'click', $.proxy( this.clear, this ) );
|
this.$clear.on( 'click', $.proxy( this.clear, this ) );
|
||||||
@@ -82,7 +78,7 @@
|
|||||||
this.toggleClear();
|
this.toggleClear();
|
||||||
},
|
},
|
||||||
|
|
||||||
keyup: function ( e ) {
|
keypress: function ( e ) {
|
||||||
var suggestion, query, languageFilter;
|
var suggestion, query, languageFilter;
|
||||||
|
|
||||||
switch ( e.keyCode ) {
|
switch ( e.keyCode ) {
|
||||||
@@ -107,11 +103,11 @@
|
|||||||
query = $.trim( this.$element.val() ).toLowerCase();
|
query = $.trim( this.$element.val() ).toLowerCase();
|
||||||
|
|
||||||
if ( this.selectedLanguage ) {
|
if ( this.selectedLanguage ) {
|
||||||
// this.selectLanguage will be populated from a matching search
|
// this.selectLanguage will be populated from a matching search
|
||||||
this.options.onSelect( this.selectedLanguage );
|
this.options.onSelect( this.selectedLanguage );
|
||||||
} else if ( this.options.languages[ query ] ) {
|
} else if ( this.options.languages[ query ] ) {
|
||||||
// Search is yet to happen (in timeout delay),
|
// Search is yet to happen (in timeout delay),
|
||||||
// but we have a matching language code.
|
// but we have a matching language code.
|
||||||
this.options.onSelect( query );
|
this.options.onSelect( query );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,9 +116,9 @@
|
|||||||
languageFilter = this;
|
languageFilter = this;
|
||||||
|
|
||||||
if ( e.which < 32 &&
|
if ( e.which < 32 &&
|
||||||
e.which !== 8 // Backspace
|
e.which !== 8 // Backspace
|
||||||
) {
|
) {
|
||||||
// ignore any ASCII control characters
|
// ignore any ASCII control characters
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,17 +317,6 @@
|
|||||||
matcher.test( $.uls.data.getAutonym( langCode ) ) ||
|
matcher.test( $.uls.data.getAutonym( langCode ) ) ||
|
||||||
matcher.test( langCode ) ||
|
matcher.test( langCode ) ||
|
||||||
matcher.test( $.uls.data.getScript( langCode ) );
|
matcher.test( $.uls.data.getScript( langCode ) );
|
||||||
},
|
|
||||||
|
|
||||||
eventSupported: function ( eventName ) {
|
|
||||||
var isSupported = eventName in this.$element;
|
|
||||||
|
|
||||||
if ( !isSupported ) {
|
|
||||||
this.$element.setAttribute( eventName, 'return;' );
|
|
||||||
isSupported = typeof this.$element[ eventName ] === 'function';
|
|
||||||
}
|
|
||||||
|
|
||||||
return isSupported;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user