( selector, context, results, seed )
| 5456 | } |
| 5457 | |
| 5458 | function select( selector, context, results, seed ) { |
| 5459 | var i, tokens, token, type, find, |
| 5460 | match = tokenize( selector ); |
| 5461 | |
| 5462 | if ( !seed ) { |
| 5463 | // Try to minimize operations if there is only one group |
| 5464 | if ( match.length === 1 ) { |
| 5465 | |
| 5466 | // Take a shortcut and set the context if the root selector is an ID |
| 5467 | tokens = match[0] = match[0].slice( 0 ); |
| 5468 | if ( tokens.length > 2 && (token = tokens[0]).type === "ID" && |
| 5469 | context.nodeType === 9 && !documentIsXML && |
| 5470 | Expr.relative[ tokens[1].type ] ) { |
| 5471 | |
| 5472 | context = Expr.find["ID"]( token.matches[0].replace( runescape, funescape ), context )[0]; |
| 5473 | if ( !context ) { |
| 5474 | return results; |
| 5475 | } |
| 5476 | |
| 5477 | selector = selector.slice( tokens.shift().value.length ); |
| 5478 | } |
| 5479 | |
| 5480 | // Fetch a seed set for right-to-left matching |
| 5481 | i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length; |
| 5482 | while ( i-- ) { |
| 5483 | token = tokens[i]; |
| 5484 | |
| 5485 | // Abort if we hit a combinator |
| 5486 | if ( Expr.relative[ (type = token.type) ] ) { |
| 5487 | break; |
| 5488 | } |
| 5489 | if ( (find = Expr.find[ type ]) ) { |
| 5490 | // Search, expanding context for leading sibling combinators |
| 5491 | if ( (seed = find( |
| 5492 | token.matches[0].replace( runescape, funescape ), |
| 5493 | rsibling.test( tokens[0].type ) && context.parentNode || context |
| 5494 | )) ) { |
| 5495 | |
| 5496 | // If seed is empty or no tokens remain, we can return early |
| 5497 | tokens.splice( i, 1 ); |
| 5498 | selector = seed.length && toSelector( tokens ); |
| 5499 | if ( !selector ) { |
| 5500 | push.apply( results, slice.call( seed, 0 ) ); |
| 5501 | return results; |
| 5502 | } |
| 5503 | |
| 5504 | break; |
| 5505 | } |
| 5506 | } |
| 5507 | } |
| 5508 | } |
| 5509 | } |
| 5510 | |
| 5511 | // Compile and execute a filtering function |
| 5512 | // Provide `match` to avoid retokenization if we modified the selector above |
| 5513 | compile( selector, match )( |
| 5514 | seed, |
| 5515 | context, |
no test coverage detected