From d920ac68fdc7c0fc95ec2e9d9c1a4a17d024581b Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Fri, 23 Sep 2011 09:11:02 -0400 Subject: [PATCH] Simplify the `.closest(Array)` code since we no longer use it internally. 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 https://github.com/jquery/jquery/commit/70e2e32e0eb03607ad0c8b7752dbd7747da47164 for that commit. --- src/traversing.js | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/src/traversing.js b/src/traversing.js index fa9462216..d385df85a 100644 --- a/src/traversing.js +++ b/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; -- 2.39.5