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