| 1 | define( [
|
| 2 | "../core",
|
| 3 | "../var/indexOf",
|
| 4 | "../var/isFunction",
|
| 5 | "./var/rneedsContext",
|
| 6 | "../selector"
|
| 7 | ], function( jQuery, indexOf, isFunction, rneedsContext ) {
|
| 8 |
|
| 9 | "use strict";
|
| 10 |
|
| 11 |
|
| 12 | function winnow( elements, qualifier, not ) {
|
| 13 | if ( isFunction( qualifier ) ) {
|
| 14 | return jQuery.grep( elements, function( elem, i ) {
|
| 15 | return !!qualifier.call( elem, i, elem ) !== not;
|
| 16 | } );
|
| 17 | }
|
| 18 |
|
| 19 |
|
| 20 | if ( qualifier.nodeType ) {
|
| 21 | return jQuery.grep( elements, function( elem ) {
|
| 22 | return ( elem === qualifier ) !== not;
|
| 23 | } );
|
| 24 | }
|
| 25 |
|
| 26 |
|
| 27 | if ( typeof qualifier !== "string" ) {
|
| 28 | return jQuery.grep( elements, function( elem ) {
|
| 29 | return ( indexOf.call( qualifier, elem ) > -1 ) !== not;
|
| 30 | } );
|
| 31 | }
|
| 32 |
|
| 33 |
|
| 34 | return jQuery.filter( qualifier, elements, not );
|
| 35 | }
|
| 36 |
|
| 37 | jQuery.filter = function( expr, elems, not ) {
|
| 38 | var elem = elems[ 0 ];
|
| 39 |
|
| 40 | if ( not ) {
|
| 41 | expr = ":not(" + expr + ")";
|
| 42 | }
|
| 43 |
|
| 44 | if ( elems.length === 1 && elem.nodeType === 1 ) {
|
| 45 | return jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [];
|
| 46 | }
|
| 47 |
|
| 48 | return jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
|
| 49 | return elem.nodeType === 1;
|
| 50 | } ) );
|
| 51 | };
|
| 52 |
|
| 53 | jQuery.fn.extend( {
|
| 54 | find: function( selector ) {
|
| 55 | var i, ret,
|
| 56 | len = this.length,
|
| 57 | self = this;
|
| 58 |
|
| 59 | if ( typeof selector !== "string" ) {
|
| 60 | return this.pushStack( jQuery( selector ).filter( function() {
|
| 61 | for ( i = 0; i < len; i++ ) {
|
| 62 | if ( jQuery.contains( self[ i ], this ) ) {
|
| 63 | return true;
|
| 64 | }
|
| 65 | }
|
| 66 | } ) );
|
| 67 | }
|
| 68 |
|
| 69 | ret = this.pushStack( [] );
|
| 70 |
|
| 71 | for ( i = 0; i < len; i++ ) {
|
| 72 | jQuery.find( selector, self[ i ], ret );
|
| 73 | }
|
| 74 |
|
| 75 | return len > 1 ? jQuery.uniqueSort( ret ) : ret;
|
| 76 | },
|
| 77 | filter: function( selector ) {
|
| 78 | return this.pushStack( winnow( this, selector || [], false ) );
|
| 79 | },
|
| 80 | not: function( selector ) {
|
| 81 | return this.pushStack( winnow( this, selector || [], true ) );
|
| 82 | },
|
| 83 | is: function( selector ) {
|
| 84 | return !!winnow(
|
| 85 | this,
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 | typeof selector === "string" && rneedsContext.test( selector ) ?
|
| 90 | jQuery( selector ) :
|
| 91 | selector || [],
|
| 92 | false
|
| 93 | ).length;
|
| 94 | }
|
| 95 | } );
|
| 96 |
|
| 97 | } );
|