MCPcopy Index your code
hub / github.com/jquery/jquery / select

Function select

src/selector.js:1288–1362  ·  view source on GitHub ↗

* 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 )

Source from the content-addressed store, hash-verified

1286 * @param {Array} [seed] A set of elements to match against
1287 */
1288function select( selector, context, results, seed ) {
1289 var i, tokens, token, type, find,
1290 compiled = typeof selector === "function" && selector,
1291 match = !seed && tokenize( ( selector = compiled.selector || selector ) );
1292
1293 results = results || [];
1294
1295 // Try to minimize operations if there is only one selector in the list and no seed
1296 // (the latter of which guarantees us context)
1297 if ( match.length === 1 ) {
1298
1299 // Reduce context if the leading compound selector is an ID
1300 tokens = match[ 0 ] = match[ 0 ].slice( 0 );
1301 if ( tokens.length > 2 && ( token = tokens[ 0 ] ).type === "ID" &&
1302 context.nodeType === 9 && documentIsHTML &&
1303 jQuery.expr.relative[ tokens[ 1 ].type ] ) {
1304
1305 context = ( jQuery.expr.find.ID(
1306 unescapeSelector( token.matches[ 0 ] ),
1307 context
1308 ) || [] )[ 0 ];
1309 if ( !context ) {
1310 return results;
1311
1312 // Precompiled matchers will still verify ancestry, so step up a level
1313 } else if ( compiled ) {
1314 context = context.parentNode;
1315 }
1316
1317 selector = selector.slice( tokens.shift().value.length );
1318 }
1319
1320 // Fetch a seed set for right-to-left matching
1321 i = matchExpr.needsContext.test( selector ) ? 0 : tokens.length;
1322 while ( i-- ) {
1323 token = tokens[ i ];
1324
1325 // Abort if we hit a combinator
1326 if ( jQuery.expr.relative[ ( type = token.type ) ] ) {
1327 break;
1328 }
1329 if ( ( find = jQuery.expr.find[ type ] ) ) {
1330
1331 // Search, expanding context for leading sibling combinators
1332 if ( ( seed = find(
1333 unescapeSelector( token.matches[ 0 ] ),
1334 rsibling.test( tokens[ 0 ].type ) &&
1335 testContext( context.parentNode ) || context
1336 ) ) ) {
1337
1338 // If seed is empty or no tokens remain, we can return early
1339 tokens.splice( i, 1 );
1340 selector = seed.length && toSelector( tokens );
1341 if ( !selector ) {
1342 push.apply( results, seed );
1343 return results;
1344 }
1345

Callers 1

findFunction · 0.70

Calls 6

tokenizeFunction · 0.90
unescapeSelectorFunction · 0.90
testContextFunction · 0.90
toSelectorFunction · 0.90
findFunction · 0.70
compileFunction · 0.70

Tested by

no test coverage detected