]> source.dussan.org Git - jquery.git/commitdiff
Support event delegation with relative selectors. Fixes #10762. Closes gh-860.
authorRichard Gibson <richard.gibson@gmail.com>
Mon, 23 Jul 2012 16:48:29 +0000 (12:48 -0400)
committerTimmy Willison <timmywillisn@gmail.com>
Mon, 23 Jul 2012 16:49:45 +0000 (12:49 -0400)
src/traversing.js
test/unit/event.js

index 625b9f4c9a4511f7edc25a4f055f289e0eed2fdf..321c25197273d95a0e12b677dd3a4e239d0fa7bf 100644 (file)
@@ -1,7 +1,7 @@
 var runtil = /Until$/,
        rparentsprev = /^(?:parents|prev(?:Until|All))/,
        isSimple = /^.[^:#\[\.,]*$/,
-       POS = jQuery.expr.match.globalPOS,
+       rneedsContext = jQuery.expr.match.needsContext,
        // methods guaranteed to produce a unique set when starting from a unique set
        guaranteedUnique = {
                children: true,
@@ -72,9 +72,9 @@ jQuery.fn.extend({
        is: function( selector ) {
                return !!selector && (
                        typeof selector === "string" ?
-                               // If this is a positional selector, check membership in the returned set
+                               // If this is a positional/relative selector, check membership in the returned set
                                // so $("p:first").is("p:last") won't return true for a doc with two "p".
-                               POS.test( selector ) ?
+                               rneedsContext.test( selector ) ?
                                        jQuery( selector, this.context ).index( this[0] ) >= 0 :
                                        jQuery.filter( selector, this ).length > 0 :
                                this.filter( selector ).length > 0 );
@@ -85,7 +85,7 @@ jQuery.fn.extend({
                        i = 0,
                        l = this.length,
                        ret = [],
-                       pos = POS.test( selectors ) || typeof selectors !== "string" ?
+                       pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
                                jQuery( selectors, context || this.context ) :
                                0;
 
index 502649a90b85236b1ad9c9901f3940b7285402cf..dacb033559d8e947ce62ddb42f4279a84aec9c5a 100644 (file)
@@ -2342,17 +2342,20 @@ test("jQuery.off using dispatched jQuery.Event", function() {
                .remove();
 });
 
-test( "delegated event with delegateTarget-relative selector (#)", function() {
-       expect(1);
-       var markup = jQuery( '<ul><li><ul id="u1"><li id="f1"></li></ul></li>' ).appendTo("body");
+test( "delegated event with delegateTarget-relative selector", function() {
+       expect(2);
+       var markup = jQuery( '<ul><li><a id="a0"></a><ul id="ul0"><li><a id="a0_0"></a></li><li><a id="a0_1"></a></li></ul></li></ul>' ).appendTo("body");
 
        markup
-               .find("#u1")
-                       .on( "click", "li:first", function() {
-                               ok( this.id === "f1" , "first li under #u1 was clicked" );
+               .on( "click", ">li>a", function() {
+                       ok( this.id === "a0", "child li was clicked" );
+               })
+               .find("#ul0")
+                       .on( "click", "li:first>a", function() {
+                               ok( this.id === "a0_0" , "first li under #u10 was clicked" );
                        })
-                       .find("#f1").click().end()
                .end()
+               .find("a").click().end()
                .remove();
 });