Skip to content
Permalink
Browse files
Simplify the .closest(Array) code since we no longer use it interna…
…lly.

It was previously used in liveHandler for delegated events, but is now baked in to events.js. The signature is a strange one since it returns an array of matches, *not* a chainable jQuery object. I've marked it as deprecated.

The code is simplified by two things: 1) We don't care about optimizing the duplicate selectors case, and 2) `.is()` now handles positional selectors by looking for set membership, which eliminates the workaround that was being applied here. See 70e2e32 for that commit.
  • Loading branch information
dmethvin committed Sep 23, 2011
1 parent 6eb7567 commit d920ac68fdc7c0fc95ec2e9d9c1a4a17d024581b
Showing with 9 additions and 24 deletions.
  1. +9 −24 src/traversing.js
@@ -86,35 +86,20 @@ jQuery.fn.extend({
closest: function( selectors, context ) {
var ret = [], i, l, cur = this[0];

// Array
// Array (deprecated as of jQuery 1.7)
if ( jQuery.isArray( selectors ) ) {
var match, selector,
matches = {},
level = 1;

if ( cur && selectors.length ) {
for ( i = 0, l = selectors.length; i < l; i++ ) {
selector = selectors[i];

if ( !matches[ selector ] ) {
matches[ selector ] = POS.test( selector ) ?
jQuery( selector, context || this.context ) :
selector;
}
}
var level = 1;

while ( cur && cur.ownerDocument && cur !== context ) {
for ( selector in matches ) {
match = matches[ selector ];
while ( cur && cur.ownerDocument && cur !== context ) {
for ( i = 0; i < selectors.length; i++ ) {

if ( match.jquery ? match.index( cur ) > -1 : jQuery( cur ).is( match ) ) {
ret.push({ selector: selector, elem: cur, level: level });
}
if ( jQuery( cur ).is( selectors[ i ] ) ) {
ret.push({ selector: selectors[ i ], elem: cur, level: level });
}

cur = cur.parentNode;
level++;
}

cur = cur.parentNode;
level++;
}

return ret;

0 comments on commit d920ac6

Please sign in to comment.