aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/event.js13
-rw-r--r--test/unit/event.js9
2 files changed, 10 insertions, 12 deletions
diff --git a/src/event.js b/src/event.js
index d56c44a55..199110c00 100644
--- a/src/event.js
+++ b/src/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 ) ) {
diff --git a/test/unit/event.js b/test/unit/event.js
index 70d616008..fb42bec35 100644
--- a/test/unit/event.js
+++ b/test/unit/event.js
@@ -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() {