( matcher, combinator, base )
| 2167 | } |
| 2168 | |
| 2169 | function addCombinator( matcher, combinator, base ) { |
| 2170 | var dir = combinator.dir, |
| 2171 | skip = combinator.next, |
| 2172 | key = skip || dir, |
| 2173 | checkNonElements = base && key === "parentNode", |
| 2174 | doneName = done++; |
| 2175 | |
| 2176 | return combinator.first ? |
| 2177 | |
| 2178 | // Check against closest ancestor/preceding element |
| 2179 | function( elem, context, xml ) { |
| 2180 | while ( ( elem = elem[ dir ] ) ) { |
| 2181 | if ( elem.nodeType === 1 || checkNonElements ) { |
| 2182 | return matcher( elem, context, xml ); |
| 2183 | } |
| 2184 | } |
| 2185 | return false; |
| 2186 | } : |
| 2187 | |
| 2188 | // Check against all ancestor/preceding elements |
| 2189 | function( elem, context, xml ) { |
| 2190 | var oldCache, outerCache, |
| 2191 | newCache = [ dirruns, doneName ]; |
| 2192 | |
| 2193 | // We can't set arbitrary data on XML nodes, so they don't benefit from combinator caching |
| 2194 | if ( xml ) { |
| 2195 | while ( ( elem = elem[ dir ] ) ) { |
| 2196 | if ( elem.nodeType === 1 || checkNonElements ) { |
| 2197 | if ( matcher( elem, context, xml ) ) { |
| 2198 | return true; |
| 2199 | } |
| 2200 | } |
| 2201 | } |
| 2202 | } else { |
| 2203 | while ( ( elem = elem[ dir ] ) ) { |
| 2204 | if ( elem.nodeType === 1 || checkNonElements ) { |
| 2205 | outerCache = elem[ expando ] || ( elem[ expando ] = {} ); |
| 2206 | |
| 2207 | if ( skip && nodeName( elem, skip ) ) { |
| 2208 | elem = elem[ dir ] || elem; |
| 2209 | } else if ( ( oldCache = outerCache[ key ] ) && |
| 2210 | oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) { |
| 2211 | |
| 2212 | // Assign to newCache so results back-propagate to previous elements |
| 2213 | return ( newCache[ 2 ] = oldCache[ 2 ] ); |
| 2214 | } else { |
| 2215 | |
| 2216 | // Reuse newcache so results back-propagate to previous elements |
| 2217 | outerCache[ key ] = newCache; |
| 2218 | |
| 2219 | // A match means we're done; a fail means we have to keep checking |
| 2220 | if ( ( newCache[ 2 ] = matcher( elem, context, xml ) ) ) { |
| 2221 | return true; |
| 2222 | } |
| 2223 | } |
| 2224 | } |
| 2225 | } |
| 2226 | } |
no test coverage detected