1 import { jQuery } from "../core.js";
2 import { indexOf } from "../var/indexOf.js";
3 import { rneedsContext } from "./var/rneedsContext.js";
5 import "../selector.js";
7 // Implement the identical functionality for filter and not
8 function winnow( elements, qualifier, not ) {
9 if ( typeof qualifier === "function" ) {
10 return jQuery.grep( elements, function( elem, i ) {
11 return !!qualifier.call( elem, i, elem ) !== not;
16 if ( qualifier.nodeType ) {
17 return jQuery.grep( elements, function( elem ) {
18 return ( elem === qualifier ) !== not;
22 // Arraylike of elements (jQuery, arguments, Array)
23 if ( typeof qualifier !== "string" ) {
24 return jQuery.grep( elements, function( elem ) {
25 return ( indexOf.call( qualifier, elem ) > -1 ) !== not;
29 // Filtered directly for both simple and complex selectors
30 return jQuery.filter( qualifier, elements, not );
33 jQuery.filter = function( expr, elems, not ) {
34 var elem = elems[ 0 ];
37 expr = ":not(" + expr + ")";
40 if ( elems.length === 1 && elem.nodeType === 1 ) {
41 return jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [];
44 return jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
45 return elem.nodeType === 1;
50 find: function( selector ) {
55 if ( typeof selector !== "string" ) {
56 return this.pushStack( jQuery( selector ).filter( function() {
57 for ( i = 0; i < len; i++ ) {
58 if ( jQuery.contains( self[ i ], this ) ) {
65 ret = this.pushStack( [] );
67 for ( i = 0; i < len; i++ ) {
68 jQuery.find( selector, self[ i ], ret );
71 return len > 1 ? jQuery.uniqueSort( ret ) : ret;
73 filter: function( selector ) {
74 return this.pushStack( winnow( this, selector || [], false ) );
76 not: function( selector ) {
77 return this.pushStack( winnow( this, selector || [], true ) );
79 is: function( selector ) {
83 // If this is a positional/relative selector, check membership in the returned set
84 // so $("p:first").is("p:last") won't return true for a doc with two "p".
85 typeof selector === "string" && rneedsContext.test( selector ) ?