Skip to content

Commit

Permalink
Core: autoDocument to control setDocument() auto-switch - patching jq…
Browse files Browse the repository at this point in the history
  • Loading branch information
wojwal committed Oct 18, 2016
1 parent abde99f commit 34cfbf5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/sizzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ function Sizzle( selector, context, results, seed ) {
// Try to shortcut find operations (as opposed to filters) in HTML documents
if ( !seed ) {

if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {
if ( Sizzle.autoDocument && ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {
setDocument( context );
}
context = context || document;
Expand Down Expand Up @@ -562,6 +562,9 @@ isXML = Sizzle.isXML = function( elem ) {
return documentElement ? documentElement.nodeName !== "HTML" : false;
};

//Global variable to control if setDocument should auto-switch current document
Sizzle.autoDocument = true;

/**
* Sets document-related variables once based on the current document
* @param {Element|Object} [doc] An element or document object to use to set the document
Expand Down Expand Up @@ -977,7 +980,7 @@ Sizzle.matches = function( expr, elements ) {

Sizzle.matchesSelector = function( elem, expr ) {
// Set document vars if needed
if ( ( elem.ownerDocument || elem ) !== document ) {
if ( Sizzle.autoDocument && ( elem.ownerDocument || elem ) !== document ) {
setDocument( elem );
}

Expand Down Expand Up @@ -1007,15 +1010,15 @@ Sizzle.matchesSelector = function( elem, expr ) {

Sizzle.contains = function( context, elem ) {
// Set document vars if needed
if ( ( context.ownerDocument || context ) !== document ) {
if ( Sizzle.autoDocument && ( context.ownerDocument || context ) !== document ) {
setDocument( context );
}
return contains( context, elem );
};

Sizzle.attr = function( elem, name ) {
// Set document vars if needed
if ( ( elem.ownerDocument || elem ) !== document ) {
if ( Sizzle.autoDocument && ( elem.ownerDocument || elem ) !== document ) {
setDocument( elem );
}

Expand Down Expand Up @@ -1991,7 +1994,7 @@ function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
for ( ; i !== len && (elem = elems[i]) != null; i++ ) {
if ( byElement && elem ) {
j = 0;
if ( !context && elem.ownerDocument !== document ) {
if ( Sizzle.autoDocument && !context && elem.ownerDocument !== document ) {
setDocument( elem );
xml = !documentIsHTML;
}
Expand Down

0 comments on commit 34cfbf5

Please sign in to comment.