Skip to content
Permalink
Browse files

Moves key event fixes to own even prop hook defs

  • Loading branch information...
rwaldron committed Sep 22, 2011
1 parent 9ef0394 commit 313bee9de4b2a3ddf9b72c3f3e0c7fd55845e2ee
Showing with 23 additions and 14 deletions.
  1. +23 −14 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 );

0 comments on commit 313bee9

Please sign in to comment.
You can’t perform that action at this time.