Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -195,99 +195,103 @@ function Sizzle( selector, context, results, seed ) {
// QSA vars
i, groups, old, nid, newContext, newSelector;

if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {
setDocument( context );
}

context = context || document;
results = results || [];
nodeType = context.nodeType;

if ( typeof selector !== "string" || !selector ||
context && (nodeType = context.nodeType) &&
nodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) {

return results;
}

if ( !seed && documentIsHTML ) {

// Try to shortcut find operations when possible (e.g., not under DocumentFragment)
if ( nodeType !== 11 && (match = rquickExpr.exec( selector )) ) {
// Speed-up: Sizzle("#ID")
if ( (m = match[1]) ) {
if ( nodeType === 9 ) {
elem = context.getElementById( m );
// Check parentNode to catch when Blackberry 4.6 returns
// nodes that are no longer in the document (jQuery #6963)
if ( elem && elem.parentNode ) {
// Handle the case where IE, Opera, and Webkit return items
// by name instead of ID
if ( elem.id === m ) {
results.push( elem );
if ( !seed ) {

if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {
setDocument( context );
}

if ( documentIsHTML ) {
context = context || document;
nodeType = context.nodeType;

// Try to shortcut find operations when possible (e.g., not under DocumentFragment)
if ( nodeType !== 11 && (match = rquickExpr.exec( selector )) ) {
// Speed-up: Sizzle("#ID")
if ( (m = match[1]) ) {
if ( nodeType === 9 ) {
elem = context.getElementById( m );
// Check parentNode to catch when Blackberry 4.6 returns
// nodes that are no longer in the document (jQuery #6963)
if ( elem && elem.parentNode ) {
// Handle the case where IE, Opera, and Webkit return items
// by name instead of ID
if ( elem.id === m ) {
results.push( elem );
return results;
}
} else {
return results;
}
} else {
return results;
}
} else {
// Context is not a document
if ( context.ownerDocument && (elem = context.ownerDocument.getElementById( m )) &&
contains( context, elem ) && elem.id === m ) {
results.push( elem );
return results;
// Context is not a document
if ( context.ownerDocument && (elem = context.ownerDocument.getElementById( m )) &&
contains( context, elem ) && elem.id === m ) {
results.push( elem );
return results;
}
}
}

// Speed-up: Sizzle("TAG")
} else if ( match[2] ) {
push.apply( results, context.getElementsByTagName( selector ) );
return results;
// Speed-up: Sizzle("TAG")
} else if ( match[2] ) {
push.apply( results, context.getElementsByTagName( selector ) );
return results;

// Speed-up: Sizzle(".CLASS")
} else if ( (m = match[3]) && support.getElementsByClassName ) {
push.apply( results, context.getElementsByClassName( m ) );
return results;
// Speed-up: Sizzle(".CLASS")
} else if ( (m = match[3]) && support.getElementsByClassName ) {
push.apply( results, context.getElementsByClassName( m ) );
return results;
}
}
}

// QSA path
if ( support.qsa && !compilerCache[ selector + " " ] && (!rbuggyQSA || !rbuggyQSA.test( selector )) ) {
nid = old = expando;
newContext = context;
newSelector = nodeType !== 1 && selector;

// qSA works strangely on Element-rooted queries
// We can work around this by specifying an extra ID on the root
// and working up from there (Thanks to Andrew Dupont for the technique)
// IE 8 doesn't work on object elements
if ( nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
groups = tokenize( selector );

if ( (old = context.getAttribute("id")) ) {
nid = old.replace( rescape, "\\$&" );
} else {
context.setAttribute( "id", nid );
}
nid = "[id='" + nid + "'] ";
// QSA path
if ( support.qsa && !compilerCache[ selector + " " ] && (!rbuggyQSA || !rbuggyQSA.test( selector )) ) {
nid = old = expando;
newContext = context;
newSelector = nodeType !== 1 && selector;

// qSA works strangely on Element-rooted queries
// We can work around this by specifying an extra ID on the root
// and working up from there (Thanks to Andrew Dupont for the technique)
// IE 8 doesn't work on object elements
if ( nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
groups = tokenize( selector );

if ( (old = context.getAttribute("id")) ) {
nid = old.replace( rescape, "\\$&" );
} else {
context.setAttribute( "id", nid );
}
nid = "[id='" + nid + "'] ";

i = groups.length;
while ( i-- ) {
groups[i] = nid + toSelector( groups[i] );
i = groups.length;
while ( i-- ) {
groups[i] = nid + toSelector( groups[i] );
}
newContext = rsibling.test( selector ) && testContext( context.parentNode ) || context;
newSelector = groups.join(",");
}
newContext = rsibling.test( selector ) && testContext( context.parentNode ) || context;
newSelector = groups.join(",");
}

if ( newSelector ) {
try {
push.apply( results,
newContext.querySelectorAll( newSelector )
);
return results;
} catch ( qsaError ) {
} finally {
if ( !old ) {
context.removeAttribute("id");
if ( newSelector ) {
try {
push.apply( results,
newContext.querySelectorAll( newSelector )
);
return results;
} catch ( qsaError ) {
} finally {
if ( !old ) {
context.removeAttribute("id");
}
}
}
}
@@ -1794,7 +1798,7 @@ function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
contextBackup = outermostContext,
// We must always have either seed elements or outermost context
elems = seed || byElement && Expr.find["TAG"]( "*", outermost ),
// Use integer dirruns iff this is the outermost matcher
// Use integer dirruns if this is the outermost matcher
dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1),
len = elems.length;

@@ -1809,6 +1813,10 @@ function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
for ( ; i !== len && (elem = elems[i]) != null; i++ ) {
if ( byElement && elem ) {
j = 0;
if ( !context && ( elem.ownerDocument || elem ) !== document ) {
setDocument( elem );
context = document;
}
while ( (matcher = elementMatchers[j++]) ) {
if ( matcher( elem, context, xml ) ) {
results.push( elem );
@@ -1985,7 +1993,7 @@ select = Sizzle.select = function( selector, context, results, seed ) {
context,
!documentIsHTML,
results,
rsibling.test( selector ) && testContext( context.parentNode ) || context
rsibling.test( selector ) && context && testContext( context.parentNode ) || context
);
return results;
};
@@ -1267,6 +1267,28 @@ test("matchesSelector", function() {
ok( !Sizzle.matchesSelector( disconnected, "* > *" ), "child combinator fails in fragment" );
});

test("matches", function() {
expect( 3 );

var iframeChild,
input = document.getElementById( "text1" ),
div = document.createElement( "div" ),
iframe = document.getElementById( "iframe" ),
iframeDoc = iframe.contentDocument || iframe.contentWindow.document;

deepEqual( Sizzle.matches( "input", [ input ] ), [ input ], "Sizzle.matches with seed of input element" );
deepEqual( Sizzle.matches( "div", [ div ] ), [ div ], "Sizzle.matches with disconnected element" );

iframeDoc.open();
iframeDoc.write( "<body><div id='foo'><div id='bar'></div></div></body>" );
iframeDoc.close();

iframeChild = iframeDoc.getElementById( "bar" );

deepEqual( Sizzle.matches( ":root > body > #foo > #bar", [ iframeChild ] ), [ iframeChild ],
"Sizzle.matches infers context from element" );
});

test("select() with pre-compiled function", function() {
expect( 6 );