Removing unique check on closest(Array) (it wasn't appropriate there and broke functionality elsewhere) - follow-up to commit 8c41325a08
. Also added another test for closest(Array) after a discussion with @jitter in 26b0e913dd
.
This commit is contained in:
parent
8c41325a08
commit
7be11207b9
2 changed files with 9 additions and 2 deletions
|
@ -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;
|
||||
});
|
||||
|
||||
|
|
|
@ -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])" );
|
||||
|
|
Loading…
Add table
Reference in a new issue