MCPcopy Create free account
hub / github.com/JsAaron/jQuery / addCombinator

Function addCombinator

2.1.1/test/jquery-2.1.1.js:2065–2116  ·  view source on GitHub ↗
( matcher, combinator, base )

Source from the content-addressed store, hash-verified

2063}
2064
2065function addCombinator( matcher, combinator, base ) {
2066 var dir = combinator.dir,
2067 checkNonElements = base && dir === "parentNode",
2068 doneName = done++;
2069
2070 return combinator.first ?
2071 // Check against closest ancestor/preceding element
2072 function( elem, context, xml ) {
2073 while ( (elem = elem[ dir ]) ) {
2074 if ( elem.nodeType === 1 || checkNonElements ) {
2075 return matcher( elem, context, xml );
2076 }
2077 }
2078 } :
2079
2080 // Check against all ancestor/preceding elements
2081 function( elem, context, xml ) {
2082 var oldCache, outerCache,
2083 newCache = [ dirruns, doneName ];
2084
2085 // We can't set arbitrary data on XML nodes, so they don't benefit from dir caching
2086 if ( xml ) {
2087 while ( (elem = elem[ dir ]) ) {
2088 if ( elem.nodeType === 1 || checkNonElements ) {
2089 if ( matcher( elem, context, xml ) ) {
2090 return true;
2091 }
2092 }
2093 }
2094 } else {
2095 while ( (elem = elem[ dir ]) ) {
2096 if ( elem.nodeType === 1 || checkNonElements ) {
2097 outerCache = elem[ expando ] || (elem[ expando ] = {});
2098 if ( (oldCache = outerCache[ dir ]) &&
2099 oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) {
2100
2101 // Assign to newCache so results back-propagate to previous elements
2102 return (newCache[ 2 ] = oldCache[ 2 ]);
2103 } else {
2104 // Reuse newcache so results back-propagate to previous elements
2105 outerCache[ dir ] = newCache;
2106
2107 // A match means we're done; a fail means we have to keep checking
2108 if ( (newCache[ 2 ] = matcher( elem, context, xml )) ) {
2109 return true;
2110 }
2111 }
2112 }
2113 }
2114 }
2115 };
2116}
2117
2118function elementMatcher( matchers ) {
2119 return matchers.length > 1 ?

Callers 1

matcherFromTokensFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected