Bug Tracker

Modify

Ticket #2338 (closed bug: fixed)

Opened 5 years ago

Last modified 3 years ago

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:
Blocking: Blocked by:

Description

The current implementation of jQuery.event.fix() uses !event.which to 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 === 0 is 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.which et 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.

Attachments

jquery-which.html Download (1.3 KB) - added by DarkRyder 5 years ago.
jquery-4750-which.diff Download (691 bytes) - added by DarkRyder 5 years ago.

Change History

Changed 5 years ago by DarkRyder

Changed 5 years ago by DarkRyder

comment:2 Changed 3 years ago by john

  • Status changed from new to closed
  • Version changed from 1.2.3 to 1.4.2
  • Resolution set to fixed
  • Milestone changed from 1.2.4 to 1.4.3

comment:3 Changed 3 years ago by dmethvin

#6489 is a duplicate of this ticket.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.