mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Prevent duplicate selectors from having to match in closest.
This commit is contained in:
parent
4daae7a79f
commit
525bb27bc0
@ -56,7 +56,7 @@ jQuery.fn.extend({
|
|||||||
|
|
||||||
closest: function( selectors, context ) {
|
closest: function( selectors, context ) {
|
||||||
if ( jQuery.isArray( selectors ) ) {
|
if ( jQuery.isArray( selectors ) ) {
|
||||||
var ret = [], cur = this[0], selector;
|
var ret = [], cur = this[0], match, selector, done;
|
||||||
|
|
||||||
if ( cur && selectors.length ) {
|
if ( cur && selectors.length ) {
|
||||||
for ( var i = 0, l = selectors.length; i < l; i++ ) {
|
for ( var i = 0, l = selectors.length; i < l; i++ ) {
|
||||||
@ -67,11 +67,18 @@ jQuery.fn.extend({
|
|||||||
|
|
||||||
while ( cur && cur.ownerDocument && cur !== context ) {
|
while ( cur && cur.ownerDocument && cur !== context ) {
|
||||||
for ( var i = 0; i < selectors.length; i++ ) {
|
for ( var i = 0; i < selectors.length; i++ ) {
|
||||||
selector = selectors[i];
|
match = selectors[i];
|
||||||
if ( selector.jquery ? selector.index(cur) > -1 : jQuery(cur).is(selector) ) {
|
selector = match.selector || match;
|
||||||
selector = selector.selector || selector;
|
|
||||||
|
// Get rid of duplicate selectors
|
||||||
|
if ( selector === done ) {
|
||||||
|
selectors.splice(i--, 1);
|
||||||
|
|
||||||
|
// See if we have a match
|
||||||
|
} else if ( match.jquery ? match.index(cur) > -1 : jQuery(cur).is(match) ) {
|
||||||
ret.push({ selector: selector, elem: cur });
|
ret.push({ selector: selector, elem: cur });
|
||||||
selectors.splice(i--, 1);
|
selectors.splice(i--, 1);
|
||||||
|
done = selector;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cur = cur.parentNode;
|
cur = cur.parentNode;
|
||||||
|
Loading…
Reference in New Issue
Block a user