Fix #10794. .triggerHandler() should not .preventDefault().

This also provides a resolution for #10699.
This commit is contained in:
Dave Methvin 2011-11-15 10:22:32 -05:00
parent 20cbf1b123
commit 6736dd7168
2 changed files with 10 additions and 12 deletions

View File

@ -281,11 +281,6 @@ jQuery.event = {
event.namespace_re = event.namespace? new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.)?") + "(\\.|$)") : null;
ontype = type.indexOf( ":" ) < 0 ? "on" + type : "";
// triggerHandler() and global events don't bubble or run the default action
if ( onlyHandlers || !elem ) {
event.preventDefault();
}
// Handle a global trigger
if ( !elem ) {
@ -335,7 +330,7 @@ jQuery.event = {
}
// Fire handlers on the event path
for ( i = 0; i < eventPath.length; i++ ) {
for ( i = 0; i < eventPath.length && !event.isPropagationStopped(); i++ ) {
cur = eventPath[i][0];
event.type = eventPath[i][1];
@ -349,15 +344,11 @@ jQuery.event = {
if ( handle && jQuery.acceptData( cur ) && handle.apply( cur, data ) === false ) {
event.preventDefault();
}
if ( event.isPropagationStopped() ) {
break;
}
}
event.type = type;
// If nobody prevented the default action, do it now
if ( !event.isDefaultPrevented() ) {
if ( !onlyHandlers && !event.isDefaultPrevented() ) {
if ( (!special._default || special._default.apply( elem.ownerDocument, data ) === false) &&
!(type === "click" && jQuery.nodeName( elem, "a" )) && jQuery.acceptData( elem ) ) {

View File

@ -1056,7 +1056,7 @@ test("trigger(type, [data], [fn])", function() {
});
test("trigger(eventObject, [data], [fn])", function() {
expect(25);
expect(28);
var $parent = jQuery("<div id='par' />").hide().appendTo("body"),
$child = jQuery("<p id='child'>foo</p>").appendTo( $parent );
@ -1132,6 +1132,13 @@ test("trigger(eventObject, [data], [fn])", function() {
$child.unbind();
$parent.unbind().remove();
// Ensure triggerHandler doesn't molest its event object (#xxx)
var event = jQuery.Event( "zowie" );
jQuery( document ).triggerHandler( event );
equal( event.type, "zowie", "Verify its type" );
equal( event.isPropagationStopped(), false, "propagation not stopped" );
equal( event.isDefaultPrevented(), false, "default not prevented" );
});
test(".trigger() bubbling on disconnected elements (#10489)", function() {