mirror of
https://github.com/jquery/jquery.git
synced 2024-10-05 11:34:18 +00:00
Traversing: Let .not(arraylike) pass non-element nodes
Fixes gh-3226 Closes gh-3261
This commit is contained in:
parent
cca2aa2254
commit
560c0c6f99
@ -15,24 +15,29 @@ function winnow( elements, qualifier, not ) {
|
||||
return jQuery.grep( elements, function( elem, i ) {
|
||||
return !!qualifier.call( elem, i, elem ) !== not;
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
// Single element
|
||||
if ( qualifier.nodeType ) {
|
||||
return jQuery.grep( elements, function( elem ) {
|
||||
return ( elem === qualifier ) !== not;
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
if ( typeof qualifier === "string" ) {
|
||||
if ( risSimple.test( qualifier ) ) {
|
||||
return jQuery.filter( qualifier, elements, not );
|
||||
}
|
||||
|
||||
qualifier = jQuery.filter( qualifier, elements );
|
||||
// Arraylike of elements (jQuery, arguments, Array)
|
||||
if ( typeof qualifier !== "string" ) {
|
||||
return jQuery.grep( elements, function( elem ) {
|
||||
return ( indexOf.call( qualifier, elem ) > -1 ) !== not;
|
||||
} );
|
||||
}
|
||||
|
||||
// Simple selector that can be filtered directly, removing non-Elements
|
||||
if ( risSimple.test( qualifier ) ) {
|
||||
return jQuery.filter( qualifier, elements, not );
|
||||
}
|
||||
|
||||
// Complex selector, compare the two sets, removing non-Elements
|
||||
qualifier = jQuery.filter( qualifier, elements );
|
||||
return jQuery.grep( elements, function( elem ) {
|
||||
return ( indexOf.call( qualifier, elem ) > -1 ) !== not && elem.nodeType === 1;
|
||||
} );
|
||||
|
@ -481,6 +481,20 @@ QUnit.test( "not(Selector) excludes non-element nodes (gh-2808)", function( asse
|
||||
assert.deepEqual( mixedContents.not( "[id=a],*,[id=b]" ).get(), [], "not [id=a],*,[id=b]" );
|
||||
} );
|
||||
|
||||
QUnit.test( "not(arraylike) passes non-element nodes (gh-3226)", function( assert ) {
|
||||
assert.expect( 5 );
|
||||
|
||||
var mixedContents = jQuery( "<span id='nonnodesElement'>hi</span> there <!-- mon ami -->" ),
|
||||
mixedLength = mixedContents.length,
|
||||
firstElement = mixedContents.first();
|
||||
|
||||
assert.deepEqual( mixedContents.not( mixedContents ).get(), [], "not everything" );
|
||||
assert.deepEqual( mixedContents.not( firstElement ).length, mixedLength - 1, "not firstElement" );
|
||||
assert.deepEqual( mixedContents.not( [ firstElement[ 0 ].nextSibling ] ).length, mixedLength - 1, "not textnode array" );
|
||||
assert.deepEqual( mixedContents.not( firstElement[ 0 ].nextSibling ).length, mixedLength - 1, "not textnode" );
|
||||
assert.deepEqual( mixedContents.not( document.body ).get(), mixedContents.get(), "not with unmatched element" );
|
||||
} );
|
||||
|
||||
QUnit.test( "has(Element)", function( assert ) {
|
||||
assert.expect( 3 );
|
||||
var obj, detached, multipleParent;
|
||||
|
Loading…
Reference in New Issue
Block a user