]> source.dussan.org Git - jquery.git/commitdiff
Fix #8165: Ignore events bubbling through disabled elements.
authorDave Methvin <dave.methvin@gmail.com>
Fri, 20 Jan 2012 03:14:24 +0000 (22:14 -0500)
committerDave Methvin <dave.methvin@gmail.com>
Fri, 20 Jan 2012 03:14:24 +0000 (22:14 -0500)
Although #6911 fixed the case where event.target was disabled, it missed the case where the target was a sub-element.

src/event.js
test/unit/event.js

index c675937a36991535f37ae07c1e711a5bd68143a1..63dd7da6bea06bcff98b2e91f03d2ce3c9352603 100644 (file)
@@ -398,33 +398,37 @@ jQuery.event = {
                event.delegateTarget = this;
 
                // Determine handlers that should run if there are delegated events
-               // Avoid disabled elements in IE (#6911) and non-left-click bubbling in Firefox (#3861)
-               if ( delegateCount && event.target.disabled !== true && !(event.button && event.type === "click") ) {
+               // Avoid non-left-click bubbling in Firefox (#3861)
+               if ( delegateCount && !(event.button && event.type === "click") ) {
 
                        // Pregenerate a single jQuery object for reuse with .is()
                        jqcur = jQuery(this);
                        jqcur.context = this.ownerDocument || this;
 
                        for ( cur = event.target; cur != this; cur = cur.parentNode || this ) {
-                               selMatch = {};
-                               matches = [];
-                               jqcur[0] = cur;
-                               for ( i = 0; i < delegateCount; i++ ) {
-                                       handleObj = handlers[ i ];
-                                       sel = handleObj.selector;
-
-                                       if ( selMatch[ sel ] === undefined ) {
-                                               selMatch[ sel ] = (
-                                                       handleObj.quick ? quickIs( cur, handleObj.quick ) : jqcur.is( sel )
-                                               );
+                       
+                               // Don't process events on disabled elements (#6911, #8165)
+                               if ( cur.disabled !== true ) {
+                                       selMatch = {};
+                                       matches = [];
+                                       jqcur[0] = cur;
+                                       for ( i = 0; i < delegateCount; i++ ) {
+                                               handleObj = handlers[ i ];
+                                               sel = handleObj.selector;
+
+                                               if ( selMatch[ sel ] === undefined ) {
+                                                       selMatch[ sel ] = (
+                                                               handleObj.quick ? quickIs( cur, handleObj.quick ) : jqcur.is( sel )
+                                                       );
+                                               }
+                                               if ( selMatch[ sel ] ) {
+                                                       matches.push( handleObj );
+                                               }
                                        }
-                                       if ( selMatch[ sel ] ) {
-                                               matches.push( handleObj );
+                                       if ( matches.length ) {
+                                               handlerQueue.push({ elem: cur, matches: matches });
                                        }
                                }
-                               if ( matches.length ) {
-                                       handlerQueue.push({ elem: cur, matches: matches });
-                               }
                        }
                }
 
index 0932ce8167512125523b0dd3e5bd0831b6cfdfe5..4c19016644cada9138f82e39f68193ceaf839503 100644 (file)
@@ -1213,8 +1213,8 @@ test("Delegated events in SVG (#10791)", function() {
        svg.remove();
 });
 
-test("Delegated events in forms (#10844; #11145)", function() {
-       expect(2);
+test("Delegated events in forms (#10844; #11145; #8165)", function() {
+       expect(3);
 
        // Aliases names like "id" cause havoc
        var form = jQuery(
@@ -1246,6 +1246,16 @@ test("Delegated events in forms (#10844; #11145)", function() {
                .end()
                .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();
 });