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