From: Rick Waldron Date: Thu, 22 Sep 2011 14:43:32 +0000 (-0400) Subject: Moves key event fixes to own even prop hook defs X-Git-Tag: 1.7b1~9^2~2^2~10 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=313bee9de4b2a3ddf9b72c3f3e0c7fd55845e2ee;p=jquery.git Moves key event fixes to own even prop hook defs --- diff --git a/src/event.js b/src/event.js index 7654d6f27..0986b9294 100644 --- a/src/event.js +++ b/src/event.js @@ -8,6 +8,7 @@ var rnamespaces = /\.(.*)$/, rtypenamespace = /^([^\.]*)?(?:\.(.+))?$/, rhoverHack = /\bhover(\.\S+)?/, rmouseEvent = /^(?:mouse|contextmenu)|click/, + rkeyEvent = /^(?:key)/, rquickIs = /^([\w\-]+)?(?:#([\w\-]+))?(?:\.([\w\-]+))?(?:\[([\w+\-]+)=["']?([\w\-]*)["']?\])?(?::(first-child|last-child|empty))?$/, quickPseudoMap = { "empty": "firstChild", @@ -492,6 +493,7 @@ jQuery.event = { } // Fix target property, if necessary + // Removal of this condition will crash IE6,7,8 if ( !event.target ) { // Fixes #1925 where srcElement might not be defined either event.target = event.srcElement || document; @@ -507,16 +509,6 @@ jQuery.event = { event.relatedTarget = event.fromElement === event.target ? event.toElement : event.fromElement; } - // Add which for key events - if ( event.which == null && (event.charCode != null || event.keyCode != null) ) { - event.which = event.charCode != null ? event.charCode : event.keyCode; - } - - // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs) - if ( !event.metaKey && event.ctrlKey ) { - event.metaKey = event.ctrlKey; - } - if ( this.propHooks[ event.type ] ) { event = this.propHooks[ event.type ]( event, originalEvent ); } @@ -1069,9 +1061,27 @@ jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblcl jQuery.attrFn[ name ] = true; } - // Add internal event property hooks to mouse events - if ( rmouseEvent.test( name ) ) { + // Key Event property hooks + if ( rkeyEvent.test( name ) ) { + jQuery.event.propHooks[ name ] = function( event, original ) { + + // Add which for key events + if ( event.which == null && (event.charCode != null || event.keyCode != null) ) { + event.which = event.charCode != null ? event.charCode : event.keyCode; + } + + // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs) + if ( !event.metaKey && event.ctrlKey ) { + event.metaKey = event.ctrlKey; + } + + return event; + }; + } + + // Mouse Event property hooks + if ( rmouseEvent.test( name ) ) { jQuery.event.propHooks[ name ] = function( event, original ) { var eventDocument, doc, body; @@ -1093,8 +1103,7 @@ jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblcl } return event; }; - } -}); + }}); })( jQuery );