( selector, context, results, seed )
| 2765 | } |
| 2766 | |
| 2767 | function select( selector, context, results, seed ) { |
| 2768 | var i, tokens, token, type, find, |
| 2769 | match = tokenize( selector ); |
| 2770 | |
| 2771 | if ( !seed ) { |
| 2772 | // Try to minimize operations if there is only one group |
| 2773 | if ( match.length === 1 ) { |
| 2774 | |
| 2775 | // Take a shortcut and set the context if the root selector is an ID |
| 2776 | tokens = match[0] = match[0].slice( 0 ); |
| 2777 | if ( tokens.length > 2 && (token = tokens[0]).type === "ID" && |
| 2778 | support.getById && context.nodeType === 9 && documentIsHTML && |
| 2779 | Expr.relative[ tokens[1].type ] ) { |
| 2780 | |
| 2781 | context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0]; |
| 2782 | if ( !context ) { |
| 2783 | return results; |
| 2784 | } |
| 2785 | selector = selector.slice( tokens.shift().value.length ); |
| 2786 | } |
| 2787 | |
| 2788 | // Fetch a seed set for right-to-left matching |
| 2789 | i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length; |
| 2790 | while ( i-- ) { |
| 2791 | token = tokens[i]; |
| 2792 | |
| 2793 | // Abort if we hit a combinator |
| 2794 | if ( Expr.relative[ (type = token.type) ] ) { |
| 2795 | break; |
| 2796 | } |
| 2797 | if ( (find = Expr.find[ type ]) ) { |
| 2798 | // Search, expanding context for leading sibling combinators |
| 2799 | if ( (seed = find( |
| 2800 | token.matches[0].replace( runescape, funescape ), |
| 2801 | rsibling.test( tokens[0].type ) && context.parentNode || context |
| 2802 | )) ) { |
| 2803 | |
| 2804 | // If seed is empty or no tokens remain, we can return early |
| 2805 | tokens.splice( i, 1 ); |
| 2806 | selector = seed.length && toSelector( tokens ); |
| 2807 | if ( !selector ) { |
| 2808 | push.apply( results, seed ); |
| 2809 | return results; |
| 2810 | } |
| 2811 | |
| 2812 | break; |
| 2813 | } |
| 2814 | } |
| 2815 | } |
| 2816 | } |
| 2817 | } |
| 2818 | |
| 2819 | // Compile and execute a filtering function |
| 2820 | // Provide `match` to avoid retokenization if we modified the selector above |
| 2821 | compile( selector, match )( |
| 2822 | seed, |
| 2823 | context, |
| 2824 | !documentIsHTML, |
no test coverage detected