mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
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 70e2e32e0e
for that commit.
This commit is contained in:
parent
6eb75676c4
commit
d920ac68fd
@ -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;
|
||||
var level = 1;
|
||||
|
||||
if ( cur && selectors.length ) {
|
||||
for ( i = 0, l = selectors.length; i < l; i++ ) {
|
||||
selector = selectors[i];
|
||||
while ( cur && cur.ownerDocument && cur !== context ) {
|
||||
for ( i = 0; i < selectors.length; i++ ) {
|
||||
|
||||
if ( !matches[ selector ] ) {
|
||||
matches[ selector ] = POS.test( selector ) ?
|
||||
jQuery( selector, context || this.context ) :
|
||||
selector;
|
||||
if ( jQuery( cur ).is( selectors[ i ] ) ) {
|
||||
ret.push({ selector: selectors[ i ], elem: cur, level: level });
|
||||
}
|
||||
}
|
||||
|
||||
while ( cur && cur.ownerDocument && cur !== context ) {
|
||||
for ( selector in matches ) {
|
||||
match = matches[ selector ];
|
||||
|
||||
if ( match.jquery ? match.index( cur ) > -1 : jQuery( cur ).is( match ) ) {
|
||||
ret.push({ selector: selector, elem: cur, level: level });
|
||||
}
|
||||
}
|
||||
|
||||
cur = cur.parentNode;
|
||||
level++;
|
||||
}
|
||||
cur = cur.parentNode;
|
||||
level++;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
Loading…
Reference in New Issue
Block a user