diff --git a/src/jquery.uls.core.js b/src/jquery.uls.core.js index 17d9797..a89339a 100644 --- a/src/jquery.uls.core.js +++ b/src/jquery.uls.core.js @@ -215,7 +215,7 @@ // Handle key press events on the menu that.$menu.on('keypress', $.proxy(this.keypress, this) ) .on('keyup', $.proxy(this.keyup, this) ); - if ( $.browser.webkit || $.browser.msie ) { + if ( this.eventSupported( 'keydown' ) ) { this.$menu.on( 'keydown', $.proxy( this.keypress, this ) ); } @@ -301,8 +301,17 @@ if ( !this.shown ) { this.show(); } - } + }, + eventSupported: function ( eventName ) { + var isSupported = eventName in this.$menu; + + if ( !isSupported ) { + this.$element.setAttribute( eventName, 'return;' ); + isSupported = typeof this.$element[eventName] === 'function'; + } + return isSupported; + } }; /* ULS PLUGIN DEFINITION diff --git a/src/jquery.uls.languagefilter.js b/src/jquery.uls.languagefilter.js index 293cd1f..b72b237 100644 --- a/src/jquery.uls.languagefilter.js +++ b/src/jquery.uls.languagefilter.js @@ -50,7 +50,7 @@ listen: function() { this.$element.on( 'keypress', $.proxy( this.keyup, this ) ) .on( 'keyup', $.proxy( this.keyup, this ) ); - if ( $.browser.webkit || $.browser.msie ) { + if ( this.eventSupported( 'keydown' ) ) { this.$element.on( 'keydown', $.proxy( this.keyup, this ) ); } if ( this.$clear.length ) { @@ -250,6 +250,17 @@ matcher.test( $.uls.data.getAutonym( langCode ) ) || matcher.test( 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; } };