| 2343 | } |
| 2344 | |
| 2345 | function addCombinator( matcher, combinator, base ) { |
| 2346 | var dir = combinator.dir, |
| 2347 | checkNonElements = base && dir === "parentNode", |
| 2348 | doneName = done++; |
| 2349 | |
| 2350 | return combinator.first ? |
| 2351 | // Check against closest ancestor/preceding element |
| 2352 | function( elem, context, xml ) { |
| 2353 | while ( (elem = elem[ dir ]) ) { |
| 2354 | if ( elem.nodeType === 1 || checkNonElements ) { |
| 2355 | return matcher( elem, context, xml ); |
| 2356 | } |
| 2357 | } |
| 2358 | } : |
| 2359 | |
| 2360 | // Check against all ancestor/preceding elements |
| 2361 | function( elem, context, xml ) { |
| 2362 | var data, cache, outerCache, |
| 2363 | dirkey = dirruns + " " + doneName; |
| 2364 | |
| 2365 | // We can't set arbitrary data on XML nodes, so they don't benefit from dir caching |
| 2366 | if ( xml ) { |
| 2367 | while ( (elem = elem[ dir ]) ) { |
| 2368 | if ( elem.nodeType === 1 || checkNonElements ) { |
| 2369 | if ( matcher( elem, context, xml ) ) { |
| 2370 | return true; |
| 2371 | } |
| 2372 | } |
| 2373 | } |
| 2374 | } else { |
| 2375 | while ( (elem = elem[ dir ]) ) { |
| 2376 | if ( elem.nodeType === 1 || checkNonElements ) { |
| 2377 | outerCache = elem[ expando ] || (elem[ expando ] = {}); |
| 2378 | if ( (cache = outerCache[ dir ]) && cache[0] === dirkey ) { |
| 2379 | if ( (data = cache[1]) === true || data === cachedruns ) { |
| 2380 | return data === true; |
| 2381 | } |
| 2382 | } else { |
| 2383 | cache = outerCache[ dir ] = [ dirkey ]; |
| 2384 | cache[1] = matcher( elem, context, xml ) || cachedruns; |
| 2385 | if ( cache[1] === true ) { |
| 2386 | return true; |
| 2387 | } |
| 2388 | } |
| 2389 | } |
| 2390 | } |
| 2391 | } |
| 2392 | }; |
| 2393 | } |
| 2394 | |
| 2395 | function elementMatcher( matchers ) { |
| 2396 | return matchers.length > 1 ? |