MCPcopy
hub / github.com/jquery-backstretch/jquery-backstretch / select

Function select

libs/jquery/jquery.js:5111–5175  ·  view source on GitHub ↗
( selector, context, results, seed, xml )

Source from the content-addressed store, hash-verified

5109}
5110
5111function select( selector, context, results, seed, xml ) {
5112 var i, tokens, token, type, find,
5113 match = tokenize( selector ),
5114 j = match.length;
5115
5116 if ( !seed ) {
5117 // Try to minimize operations if there is only one group
5118 if ( match.length === 1 ) {
5119
5120 // Take a shortcut and set the context if the root selector is an ID
5121 tokens = match[0] = match[0].slice( 0 );
5122 if ( tokens.length > 2 && (token = tokens[0]).type === "ID" &&
5123 context.nodeType === 9 && !xml &&
5124 Expr.relative[ tokens[1].type ] ) {
5125
5126 context = Expr.find["ID"]( token.matches[0].replace( rbackslash, "" ), context, xml )[0];
5127 if ( !context ) {
5128 return results;
5129 }
5130
5131 selector = selector.slice( tokens.shift().length );
5132 }
5133
5134 // Fetch a seed set for right-to-left matching
5135 for ( i = matchExpr["POS"].test( selector ) ? -1 : tokens.length - 1; i >= 0; i-- ) {
5136 token = tokens[i];
5137
5138 // Abort if we hit a combinator
5139 if ( Expr.relative[ (type = token.type) ] ) {
5140 break;
5141 }
5142 if ( (find = Expr.find[ type ]) ) {
5143 // Search, expanding context for leading sibling combinators
5144 if ( (seed = find(
5145 token.matches[0].replace( rbackslash, "" ),
5146 rsibling.test( tokens[0].type ) && context.parentNode || context,
5147 xml
5148 )) ) {
5149
5150 // If seed is empty or no tokens remain, we can return early
5151 tokens.splice( i, 1 );
5152 selector = seed.length && tokens.join("");
5153 if ( !selector ) {
5154 push.apply( results, slice.call( seed, 0 ) );
5155 return results;
5156 }
5157
5158 break;
5159 }
5160 }
5161 }
5162 }
5163 }
5164
5165 // Compile and execute a filtering function
5166 // Provide `match` to avoid retokenization if we modified the selector above
5167 compile( selector, match )(
5168 seed,

Callers 1

SizzleFunction · 0.85

Calls 1

tokenizeFunction · 0.85

Tested by

no test coverage detected