Skip to content

Commit

Permalink
Allow :focus selector to pass through QSA. Breaks Chrome 21, bypasses…
Browse files Browse the repository at this point in the history
… IE8/9 throwing an error. Supplements jQuery #13378.
  • Loading branch information
timmywil committed Apr 8, 2013
1 parent f67c4a9 commit 9ff2bbb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
21 changes: 13 additions & 8 deletions dist/sizzle.js
Expand Up @@ -6,7 +6,7 @@
* Released under the MIT license
* http://jquery.org/license
*
* Date: 2013-04-04
* Date: 2013-04-08
*/
(function( window, undefined ) {

Expand Down Expand Up @@ -287,7 +287,7 @@ function Sizzle( selector, context, results, seed ) {
}

// QSA path
if ( support.qsa && !rbuggyQSA.test(selector) ) {
if ( support.qsa && (!rbuggyQSA || !rbuggyQSA.test( selector )) ) {
nid = old = expando;
newContext = context;
newSelector = nodeType === 9 && selector;
Expand Down Expand Up @@ -504,10 +504,12 @@ setDocument = Sizzle.setDocument = function( node ) {
// matchesSelector(:active) reports false when true (IE9/Opera 11.5)
rbuggyMatches = [];

// qSa(:focus) reports false when true (Chrome 21),
// no need to also add to buggyMatches since matches checks buggyQSA
// A support test would require too much code (would include document ready)
rbuggyQSA = [ ":focus" ];
// qSa(:focus) reports false when true (Chrome 21)
// We allow this because of a bug in IE8/9 that throws an error
// whenever `document.activeElement` is accessed on an iframe
// So, we allow :focus to pass through QSA all the time to avoid the IE error
// See http://bugs.jquery.com/ticket/13378
rbuggyQSA = [];

if ( (support.qsa = isNative(doc.querySelectorAll)) ) {
// Build QSA regex
Expand Down Expand Up @@ -578,7 +580,7 @@ setDocument = Sizzle.setDocument = function( node ) {
});
}

rbuggyQSA = new RegExp( rbuggyQSA.join("|") );
rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join("|") );
rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join("|") );

// Element contains another
Expand Down Expand Up @@ -712,7 +714,10 @@ Sizzle.matchesSelector = function( elem, expr ) {
expr = expr.replace( rattributeQuotes, "='$1']" );

// rbuggyQSA always contains :focus, so no need for an existence check
if ( support.matchesSelector && documentIsHTML && (!rbuggyMatches || !rbuggyMatches.test(expr)) && !rbuggyQSA.test(expr) ) {
if ( support.matchesSelector && documentIsHTML &&
(!rbuggyMatches || !rbuggyMatches.test(expr)) &&
(!rbuggyQSA || !rbuggyQSA.test(expr)) ) {

try {
var ret = matches.call( elem, expr );

Expand Down
2 changes: 1 addition & 1 deletion dist/sizzle.min.js

Large diffs are not rendered by default.

0 comments on commit 9ff2bbb

Please sign in to comment.