Commit 8d9025ca authored by Dave Methvin's avatar Dave Methvin

Fix #8165: Ignore events bubbling through disabled elements.

Although #6911 fixed the case where event.target was disabled, it missed the case where the target was a sub-element.
parent 2982abbb
...@@ -398,33 +398,37 @@ jQuery.event = { ...@@ -398,33 +398,37 @@ jQuery.event = {
event.delegateTarget = this; event.delegateTarget = this;
// Determine handlers that should run if there are delegated events // Determine handlers that should run if there are delegated events
// Avoid disabled elements in IE (#6911) and non-left-click bubbling in Firefox (#3861) // Avoid non-left-click bubbling in Firefox (#3861)
if ( delegateCount && event.target.disabled !== true && !(event.button && event.type === "click") ) { if ( delegateCount && !(event.button && event.type === "click") ) {
// Pregenerate a single jQuery object for reuse with .is() // Pregenerate a single jQuery object for reuse with .is()
jqcur = jQuery(this); jqcur = jQuery(this);
jqcur.context = this.ownerDocument || this; jqcur.context = this.ownerDocument || this;
for ( cur = event.target; cur != this; cur = cur.parentNode || this ) { for ( cur = event.target; cur != this; cur = cur.parentNode || this ) {
selMatch = {};
matches = []; // Don't process events on disabled elements (#6911, #8165)
jqcur[0] = cur; if ( cur.disabled !== true ) {
for ( i = 0; i < delegateCount; i++ ) { selMatch = {};
handleObj = handlers[ i ]; matches = [];
sel = handleObj.selector; jqcur[0] = cur;
for ( i = 0; i < delegateCount; i++ ) {
if ( selMatch[ sel ] === undefined ) { handleObj = handlers[ i ];
selMatch[ sel ] = ( sel = handleObj.selector;
handleObj.quick ? quickIs( cur, handleObj.quick ) : jqcur.is( sel )
); if ( selMatch[ sel ] === undefined ) {
selMatch[ sel ] = (
handleObj.quick ? quickIs( cur, handleObj.quick ) : jqcur.is( sel )
);
}
if ( selMatch[ sel ] ) {
matches.push( handleObj );
}
} }
if ( selMatch[ sel ] ) { if ( matches.length ) {
matches.push( handleObj ); handlerQueue.push({ elem: cur, matches: matches });
} }
} }
if ( matches.length ) {
handlerQueue.push({ elem: cur, matches: matches });
}
} }
} }
......
...@@ -1213,8 +1213,8 @@ test("Delegated events in SVG (#10791)", function() { ...@@ -1213,8 +1213,8 @@ test("Delegated events in SVG (#10791)", function() {
svg.remove(); svg.remove();
}); });
test("Delegated events in forms (#10844; #11145)", function() { test("Delegated events in forms (#10844; #11145; #8165)", function() {
expect(2); expect(3);
// Aliases names like "id" cause havoc // Aliases names like "id" cause havoc
var form = jQuery( var form = jQuery(
...@@ -1246,6 +1246,16 @@ test("Delegated events in forms (#10844; #11145)", function() { ...@@ -1246,6 +1246,16 @@ test("Delegated events in forms (#10844; #11145)", function() {
.end() .end()
.off("submit"); .off("submit");
form
.append( '<button id="nestyDisabledBtn"><span>Zing</span></button>' )
.on( "click", "#nestyDisabledBtn", function() {
ok( true, "enabled/disabled button with nesty elements" );
})
.find( "span" ).trigger( "click" ).end() // yep
.find( "#nestyDisabledBtn" ).prop( "disabled", true ).end()
.find( "span" ).trigger( "click" ).end() // nope
.off( "click" );
form.remove(); form.remove();
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment