Side navigation
#2338 closed bug (fixed)
Opened February 13, 2008 07:25PM UTC
Closed September 28, 2010 10:00PM UTC
Last modified November 11, 2010 03:39AM UTC
jQuery.event.fix() mangles "event.which" when it == false
Reported by: | DarkRyder | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | 1.4.3 |
Component: | event | Version: | 1.4.2 |
Keywords: | opera keypress | Cc: | |
Blocked by: | Blocking: |
Description
The current implementation of
jQuery.event.fix()uses
!event.whichto determine whether to alter its value, which causes it to get mangled if its value is 0:
// Add which for key events if ( !event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode) ) event.which = event.charCode || event.keyCode;
This would be a non-issue except that checking whether
event.which === 0is the only way to distinguish between certain keys in Opera (notoriously, the single-quote key and the right arrow key). Below is an implementation which corrects this problem by explicitly testing whether
event.whichet al. have been defined.
// Add which for key events if ( typeof event.which == "undefined" && (typeof event.charCode != "undefined" || typeof event.keyCode != "undefined") ) event.which = typeof event.charCode != "undefined" ? event.charCode : event.keyCode;
Attached are a simple test case and a diff of event.js against revision 4750.
Fixed http://github.com/jquery/jquery/commit/e3c4e5789743eecb3cbe2b626f3a5f09c616ee4b