Skip to content

Instantly share code, notes, and snippets.

@dperini
Created October 22, 2016 17:24
Show Gist options
  • Save dperini/7089c33e443480300633cac3099147c9 to your computer and use it in GitHub Desktop.
Save dperini/7089c33e443480300633cac3099147c9 to your computer and use it in GitHub Desktop.
Simulate behavior of the new "Selectors Level 4" :scope selector
<!DOCTYPE html>
<html>
<head>
<title>NWMatcher Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../../src/nwmatcher-noqsa.js"></script>
</head>
<body>
<div class="a">
<div class="a1"></div>
<div class="a2"></div>
</div>
<script>
var aNode = NW.Dom.first('.a', document)
var entriesUnscoped = NW.Dom.select('*', aNode, function(e) { NW.Dom.match(e, 'body div'); });
var entriesScoped = NW.Dom.select('body div', aNode);
if (entriesUnscoped.length !== 2) {
console.log('1. Invalid number of entries, should be 2, got ' + entriesUnscoped.length);
} else {
console.log('1. Passed!');
}
if (entriesScoped.length !== 0) {
console.log('2. Invalid number of entries, should be 0, got ' + entriesScoped.length);
} else {
console.log('2. Passed!');
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment