Skip to content

Commit

Permalink
Moves key event fixes to own even prop hook defs
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Sep 22, 2011
1 parent 9ef0394 commit 313bee9
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/event.js
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand All @@ -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 );
}
Expand Down Expand Up @@ -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;
Expand All @@ -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.