diff options
author | Timmy Willison <timmywillisn@gmail.com> | 2013-09-09 19:13:01 -0500 |
---|---|---|
committer | Timmy Willison <timmywillisn@gmail.com> | 2013-09-09 19:13:01 -0500 |
commit | 825ac3773694e0cd23ee74895fd5aeb535b27da4 (patch) | |
tree | b389bf60adbfd0cb06a92f91ca5fc5509f66f197 /src/traversing.js | |
parent | d788010aa724f58090560e83c224d3d140814b51 (diff) | |
download | jquery-825ac3773694e0cd23ee74895fd5aeb535b27da4.tar.gz jquery-825ac3773694e0cd23ee74895fd5aeb535b27da4.zip |
Separate jQuery.fn.init into its own module (for lighter core dependencies across all modules)
Diffstat (limited to 'src/traversing.js')
-rw-r--r-- | src/traversing.js | 100 |
1 files changed, 5 insertions, 95 deletions
diff --git a/src/traversing.js b/src/traversing.js index b66a22f6d..4e55c8257 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -1,12 +1,13 @@ define([ "./core", "./var/indexOf", + "./traversing/var/rneedsContext", + "./core/init", + "./traversing/findFilter", "./selector" -], function( jQuery, indexOf ) { +], function( jQuery, indexOf, rneedsContext ) { -var isSimple = /^.[^:#\[\.,]*$/, - rparentsprev = /^(?:parents|prev(?:Until|All))/, - rneedsContext = jQuery.expr.match.needsContext, +var rparentsprev = /^(?:parents|prev(?:Until|All))/, // methods guaranteed to produce a unique set when starting from a unique set guaranteedUnique = { children: true, @@ -15,51 +16,7 @@ var isSimple = /^.[^:#\[\.,]*$/, prev: true }; -// Implement the identical functionality for filter and not -function winnow( elements, qualifier, not ) { - if ( jQuery.isFunction( qualifier ) ) { - return jQuery.grep( elements, function( elem, i ) { - /* jshint -W018 */ - return !!qualifier.call( elem, i, elem ) !== not; - }); - - } - - if ( qualifier.nodeType ) { - return jQuery.grep( elements, function( elem ) { - return ( elem === qualifier ) !== not; - }); - - } - - if ( typeof qualifier === "string" ) { - if ( isSimple.test( qualifier ) ) { - return jQuery.filter( qualifier, elements, not ); - } - - qualifier = jQuery.filter( qualifier, elements ); - } - - return jQuery.grep( elements, function( elem ) { - return ( indexOf.call( qualifier, elem ) >= 0 ) !== not; - }); -} - jQuery.extend({ - filter: function( expr, elems, not ) { - var elem = elems[ 0 ]; - - if ( not ) { - expr = ":not(" + expr + ")"; - } - - return elems.length === 1 && elem.nodeType === 1 ? - jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] : - jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) { - return elem.nodeType === 1; - })); - }, - dir: function( elem, dir, until ) { var matched = [], truncate = until !== undefined; @@ -89,32 +46,6 @@ jQuery.extend({ }); jQuery.fn.extend({ - find: function( selector ) { - var i, - ret = [], - self = this, - len = self.length; - - if ( typeof selector !== "string" ) { - return this.pushStack( jQuery( selector ).filter(function() { - for ( i = 0; i < len; i++ ) { - if ( jQuery.contains( self[ i ], this ) ) { - return true; - } - } - }) ); - } - - for ( i = 0; i < len; i++ ) { - jQuery.find( selector, self[ i ], ret ); - } - - // Needed because $( selector, context ) becomes $( context ).find( selector ) - ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret ); - ret.selector = this.selector ? this.selector + " " + selector : selector; - return ret; - }, - has: function( target ) { var targets = jQuery( target, this ), l = targets.length; @@ -129,27 +60,6 @@ jQuery.fn.extend({ }); }, - not: function( selector ) { - return this.pushStack( winnow(this, selector || [], true) ); - }, - - filter: function( selector ) { - return this.pushStack( winnow(this, selector || [], false) ); - }, - - is: function( selector ) { - return !!winnow( - this, - - // If this is a positional/relative selector, check membership in the returned set - // so $("p:first").is("p:last") won't return true for a doc with two "p". - typeof selector === "string" && rneedsContext.test( selector ) ? - jQuery( selector ) : - selector || [], - false - ).length; - }, - closest: function( selectors, context ) { var cur, i = 0, |