Skip to content
Permalink
Browse files

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

This also provides a resolution for #10699.
  • Loading branch information...
dmethvin committed Nov 15, 2011
1 parent 20cbf1b commit 6736dd7168ccd1e6d72aca2e3c89d685c5d9c63a
Showing with 10 additions and 12 deletions.
  1. +2 −11 src/event.js
  2. +8 −1 test/unit/event.js
@@ -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 ) ) {
@@ -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() {

0 comments on commit 6736dd7

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