Skip to content

Fix for matches resolving document.body at require time. #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions src/query/matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@
import canUseDOM from '../util/inDOM'
import qsa from './querySelectorAll'

let matches;
if (canUseDOM) {
let body = document.body
let nativeMatch = body.matches
|| body.matchesSelector
|| body.webkitMatchesSelector
|| body.mozMatchesSelector
|| body.msMatchesSelector;

matches = nativeMatch
? (node, selector) => nativeMatch.call(node, selector)
: ie8MatchesSelector
}
let matchesCache;

export default function matches(node, selector) {
if (!matchesCache && canUseDOM) {
let body = document.body
let nativeMatch = body.matches
|| body.matchesSelector
|| body.webkitMatchesSelector
|| body.mozMatchesSelector
|| body.msMatchesSelector;

export default matches
matchesCache = nativeMatch
? (node, selector) => nativeMatch.call(node, selector)
: ie8MatchesSelector
}

return matchesCache ?
matchesCache(node, selector) :
null;
}

function ie8MatchesSelector(node, selector) {
var matches = qsa(node.document || node.ownerDocument, selector)
Expand Down