]> source.dussan.org Git - jquery.git/commitdiff
Fix #13819: .parent sort direction
authorRichard Gibson <richard.gibson@gmail.com>
Wed, 24 Apr 2013 15:38:23 +0000 (11:38 -0400)
committerRichard Gibson <richard.gibson@gmail.com>
Wed, 24 Apr 2013 15:40:42 +0000 (11:40 -0400)
(cherry picked from commit 6a816ec95fd96d130a4af67a28873d9daa66a328)

src/traversing.js
test/unit/traversing.js

index 5e9fe19438b0e4a6ab55ab740dba1b1d35f75bcd..6f68e782123cd09bfa0c32e4b3debbd5e01a254e 100644 (file)
@@ -201,7 +201,7 @@ jQuery.each({
                        }
 
                        // Reverse order for parents* and prev*
-                       if ( name[ 0 ] === "p" ) {
+                       if ( name[ 0 ] === "p" && name !== "parent" ) {
                                matched.reverse();
                        }
                }
index e45ab75a554bdf4d932cd27b96b973b74b3d9d17..b35a5c3cce4b83368c82c97aa29140c58dc4d89c 100644 (file)
@@ -673,6 +673,32 @@ test("contents()", function() {
        equal( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" );
 });
 
+test("sort direction", function() {
+       expect( 12 );
+
+       var elems = jQuery("#ap, #select1 > *, #moretests > form"),
+               methodDirections = {
+                       parent: false,
+                       parents: true,
+                       parentsUntil: true,
+                       next: false,
+                       prev: true,
+                       nextAll: false,
+                       prevAll: true,
+                       nextUntil: false,
+                       prevUntil: true,
+                       siblings: false,
+                       children: false,
+                       contents: false
+               };
+
+       jQuery.each( methodDirections, function( method, reversed ) {
+               var actual = elems[ method ]().get(),
+                       forward = jQuery.unique( [].concat( actual ) );
+               deepEqual( actual, reversed ? forward.reverse() : forward, "Correct sort direction for " + method );
+       });
+});
+
 test("add(String|Element|Array|undefined)", function() {
        expect( 15 );