MCPcopy Index your code
hub / github.com/jquery/jquery / select

Function select

dist-module/jquery.factory.module.js:2371–2445  ·  view source on GitHub ↗

* A low-level selection function that works with jQuery's compiled * selector functions * @param {String|Function} selector A selector or a pre-compiled * selector function built with jQuery selector compile * @param {Element} context * @param {Array} [results] * @param {Array} [seed] A set

( selector, context, results, seed )

Source from the content-addressed store, hash-verified

2369 * @param {Array} [seed] A set of elements to match against
2370 */
2371function select( selector, context, results, seed ) {
2372 var i, tokens, token, type, find,
2373 compiled = typeof selector === "function" && selector,
2374 match = !seed && tokenize( ( selector = compiled.selector || selector ) );
2375
2376 results = results || [];
2377
2378 // Try to minimize operations if there is only one selector in the list and no seed
2379 // (the latter of which guarantees us context)
2380 if ( match.length === 1 ) {
2381
2382 // Reduce context if the leading compound selector is an ID
2383 tokens = match[ 0 ] = match[ 0 ].slice( 0 );
2384 if ( tokens.length > 2 && ( token = tokens[ 0 ] ).type === "ID" &&
2385 context.nodeType === 9 && documentIsHTML &&
2386 jQuery.expr.relative[ tokens[ 1 ].type ] ) {
2387
2388 context = ( jQuery.expr.find.ID(
2389 unescapeSelector( token.matches[ 0 ] ),
2390 context
2391 ) || [] )[ 0 ];
2392 if ( !context ) {
2393 return results;
2394
2395 // Precompiled matchers will still verify ancestry, so step up a level
2396 } else if ( compiled ) {
2397 context = context.parentNode;
2398 }
2399
2400 selector = selector.slice( tokens.shift().value.length );
2401 }
2402
2403 // Fetch a seed set for right-to-left matching
2404 i = matchExpr.needsContext.test( selector ) ? 0 : tokens.length;
2405 while ( i-- ) {
2406 token = tokens[ i ];
2407
2408 // Abort if we hit a combinator
2409 if ( jQuery.expr.relative[ ( type = token.type ) ] ) {
2410 break;
2411 }
2412 if ( ( find = jQuery.expr.find[ type ] ) ) {
2413
2414 // Search, expanding context for leading sibling combinators
2415 if ( ( seed = find(
2416 unescapeSelector( token.matches[ 0 ] ),
2417 rsibling.test( tokens[ 0 ].type ) &&
2418 testContext( context.parentNode ) || context
2419 ) ) ) {
2420
2421 // If seed is empty or no tokens remain, we can return early
2422 tokens.splice( i, 1 );
2423 selector = seed.length && toSelector( tokens );
2424 if ( !selector ) {
2425 push.apply( results, seed );
2426 return results;
2427 }
2428

Callers 1

findFunction · 0.70

Calls 6

tokenizeFunction · 0.70
unescapeSelectorFunction · 0.70
findFunction · 0.70
testContextFunction · 0.70
toSelectorFunction · 0.70
compileFunction · 0.70

Tested by

no test coverage detected