Showing with 27 additions and 18 deletions.
  1. +27 −18 sizzle.js
@@ -135,18 +135,29 @@ var i,
String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 );
};

// Use a stripped-down slice if we can't use a native one
// Optimize for push.apply( _, slice.call(<NodeList>, 0) )
try {
slice.call( preferredDoc.documentElement.childNodes, 0 )[0].nodeType;
push.apply(
(arr = slice.call( preferredDoc.childNodes )),
preferredDoc.childNodes
);

// Slice is trivial if apply accepts NodeLists
slice = identity;
} catch ( e ) {
slice = function( i ) {
var elem,
results = [];
while ( (elem = this[i++]) ) {
results.push( elem );
}
return results;
};
// Make sure slice accepts NodeLists
if ( !arr.length ) {
slice = function( i ) {
var results = [];
while ( (results[i] = this[i++]) ) {}
results.pop();
return results;
};
}
}

function identity() {
return this;
}

/**
@@ -371,25 +382,24 @@ setDocument = Sizzle.setDocument = function( node ) {
return div.getElementsByClassName("e").length === 2;
});

// Check if getElementById returns elements by name
// Check if getElementsByName privileges form controls or returns elements by ID
// If so, assume (for broader support) that getElementById returns elements by name
support.getByName = assert(function( div ) {
// Inject content
div.id = expando + 0;
// Support: Windows 8 Native Apps
// Assigning innerHTML with "name" attributes throws uncatchable exceptions
// http://msdn.microsoft.com/en-us/library/ie/hh465388.aspx
div.appendChild( document.createElement("a") ).setAttribute( "name", expando );
div.appendChild( document.createElement("div") ).setAttribute( "name", expando );
docElem.insertBefore( div, docElem.firstChild );
div.appendChild( document.createElement("i") ).setAttribute( "name", expando );
docElem.appendChild( div );

// Test
var pass = doc.getElementsByName &&
// buggy browsers will return fewer than the correct 2
doc.getElementsByName( expando ).length === 2 +
// buggy browsers will return more than the correct 0
doc.getElementsByName( expando + 0 ).length;
support.getIdNotName = !doc.getElementById( expando );

// Cleanup
docElem.removeChild( div );
@@ -424,7 +434,7 @@ setDocument = Sizzle.setDocument = function( node ) {
};

// ID find and filter
if ( support.getIdNotName ) {
if ( support.getByName ) {
Expr.find["ID"] = function( id, context ) {
if ( typeof context.getElementById !== strundefined && !documentIsXML ) {
var m = context.getElementById( id );
@@ -1877,9 +1887,8 @@ function select( selector, context, results, seed ) {
Expr.pseudos["nth"] = Expr.pseudos["eq"];

// Easy API for creating new setFilters
function setFilters() {}
Expr.filters = setFilters.prototype = Expr.pseudos;
Expr.setFilters = new setFilters();
identity.prototype = Expr.filters = Expr.pseudos;
Expr.setFilters = new identity();

// Initialize with the default document
setDocument();