Permalink
Browse files

Prefer checking `which` property over `keyCode`

  • Loading branch information...
1 parent 63f370f commit 92028fee52ff07e47c63c1d3bc9c00af15cd823e @timoxley committed Apr 8, 2013
Showing with 4 additions and 1 deletion.
  1. +4 −1 index.js
View
5 index.js
@@ -11,7 +11,10 @@ var has = ({}).hasOwnProperty
* @api public
*/
exports = module.exports = function(searchInput) {
- if ('object' === typeof searchInput && searchInput && has.call(searchInput, 'keyCode')) searchInput = searchInput.keyCode
+ if (searchInput && 'object' === typeof searchInput) {
+ var hasKeyCode = searchInput.which || searchInput.keyCode || searchInput.charCode
+ if (hasKeyCode) searchInput = hasKeyCode
+ }
if ('number' === typeof searchInput) return names[searchInput]
var search = String(searchInput)
var foundNamedKey = codes[search.toLowerCase()]

0 comments on commit 92028fe

Please sign in to comment.