Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
Created July 6, 2022 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nolanlawson/2f38242207bd62ddd8d4da627cfc1503 to your computer and use it in GitHub Desktop.
Save nolanlawson/2f38242207bd62ddd8d4da627cfc1503 to your computer and use it in GitHub Desktop.
Test event capture
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test event capture</title>
</head>
<body>
<h1>Test event capture</h1>
<pre id="display"></pre>
<script type="module">
const tests = [
undefined,
null,
0,
1,
"",
"foo",
true,
false,
{},
[],
{ capture: true },
{ capture: false },
{ foobar: true }
]
for (const test of tests) {
let eventPhase
const listener = (e) => {
eventPhase = e.eventPhase
}
document.addEventListener('test', listener, test)
document.body.dispatchEvent(new Event('test', { bubbles: true }))
display.innerHTML += `Test: ${test === undefined ? 'undefined' : JSON.stringify(test)} - Captures: ${eventPhase === Event.CAPTURING_PHASE}\n`
document.removeEventListener('test', listener, test)
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment