mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Don't run direct handlers if delegate did .stopPropagation().
This commit is contained in:
parent
c4cc343c9c
commit
9fabe2028f
@ -459,7 +459,7 @@ jQuery.event = {
|
|||||||
delete event.delegateTarget;
|
delete event.delegateTarget;
|
||||||
|
|
||||||
// Run non-delegated handlers for this level
|
// Run non-delegated handlers for this level
|
||||||
if ( handlers.length ) {
|
if ( handlers.length && !event.isPropagationStopped() ) {
|
||||||
dispatch( this, event, handlers, args );
|
dispatch( this, event, handlers, args );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2054,6 +2054,22 @@ test(".delegate()/.undelegate()", function() {
|
|||||||
jQuery("#body").undelegate("#nothiddendiv div", "click");
|
jQuery("#body").undelegate("#nothiddendiv div", "click");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("stopPropagation() stops directly-bound events on delegated target", function() {
|
||||||
|
expect(1);
|
||||||
|
|
||||||
|
var markup = jQuery( '<div><p><a href="#">target</a></p></div>' );
|
||||||
|
markup
|
||||||
|
.on( "click", function() {
|
||||||
|
ok( false, "directly-bound event on delegate target was called" );
|
||||||
|
})
|
||||||
|
.on( "click", "a", function( e ) {
|
||||||
|
e.stopPropagation();
|
||||||
|
ok( true, "delegated handler was called" );
|
||||||
|
})
|
||||||
|
.find("a").click().end()
|
||||||
|
.remove();
|
||||||
|
});
|
||||||
|
|
||||||
test("undelegate all bound events", function(){
|
test("undelegate all bound events", function(){
|
||||||
expect(1);
|
expect(1);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user