]> source.dussan.org Git - jquery.git/commitdiff
Removing unique check on closest(Array) (it wasn't appropriate there and broke functi...
authorjeresig <jeresig@gmail.com>
Tue, 28 Sep 2010 00:59:42 +0000 (20:59 -0400)
committerjeresig <jeresig@gmail.com>
Tue, 28 Sep 2010 00:59:42 +0000 (20:59 -0400)
src/traversing.js
test/unit/traversing.js

index f7dde44ec466d9e8d198f6bbbf86af09a4605e89..dff10875462c803779a026fbd286575d982a01df 100644 (file)
@@ -56,9 +56,11 @@ jQuery.fn.extend({
 
        closest: function( selectors, context ) {
                var ret;
+
                if ( jQuery.isArray( selectors ) ) {
                        var cur = this[0], match, matches = {}, selector, level = 1;
                        ret = [];
+
                        if ( cur && selectors.length ) {
                                for ( var i = 0, l = selectors.length; i < l; i++ ) {
                                        selector = selectors[i];
@@ -78,23 +80,27 @@ jQuery.fn.extend({
                                                        ret.push({ selector: selector, elem: cur, level: level });
                                                }
                                        }
+
                                        cur = cur.parentNode;
                                        level++;
                                }
                        }
 
-                       return ret.length > 1 ? jQuery.unique(ret) : ret;
+                       return ret;
                }
 
                var pos = jQuery.expr.match.POS.test( selectors ) ? 
                        jQuery( selectors, context || this.context ) : null;
+
                ret = jQuery.map(this.get(),function( cur,i ) {
                        while ( cur && cur.ownerDocument && cur !== context ) {
                                if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selectors) ) {
                                        return cur;
                                }
+
                                cur = cur.parentNode;
                        }
+
                        return null;
                });
                
index c7279cfe5fa75d0525722a838e01b2b1c28328a9..3fd98f674f16bbaf489d441e98fd7f2265cdb33c 100644 (file)
@@ -141,10 +141,11 @@ test("closest()", function() {
 });
 
 test("closest(Array)", function() {
-       expect(6);
+       expect(7);
        same( jQuery("body").closest(["body"]), [{selector:"body", elem:document.body, level:1}], "closest([body])" );
        same( jQuery("body").closest(["html"]), [{selector:"html", elem:document.documentElement, level:2}], "closest([html])" );
        same( jQuery("body").closest(["div"]), [], "closest([div])" );
+       same( jQuery("#yahoo").closest(["div"]), [{"selector":"div", "elem": document.getElementById("foo"), "level": 3}, { "selector": "div", "elem": document.getElementById("main"), "level": 4 }], "closest([div])" );
        same( jQuery("#main").closest(["span,#html"]), [{selector:"span,#html", elem:document.documentElement, level:4}], "closest([span,#html])" );
 
        same( jQuery("body").closest(["body","html"]), [{selector:"body", elem:document.body, level:1}, {selector:"html", elem:document.documentElement, level:2}], "closest([body, html])" );