mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Fix #10794. .triggerHandler() should not .preventDefault().
This also provides a resolution for #10699.
This commit is contained in:
parent
20cbf1b123
commit
6736dd7168
13
src/event.js
13
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 ) ) {
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user