Skip to content

Commit 12beda2

Browse files
committed
DOM Events introduction: clarify how listeners are invoked
Fixes #888.
1 parent 8f20138 commit 12beda2

File tree

1 file changed

+27
-42
lines changed

1 file changed

+27
-42
lines changed

dom.bs

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<pre class='metadata'>
1+
<pre class=metadata>
22
Group: WHATWG
33
H1: DOM
44
Shortname: dom
@@ -358,34 +358,24 @@ use of this functionality through <a>events</a>
358358
(synthetic events) can make use of the return value of the
359359
{{EventTarget/dispatchEvent()}} method:
360360

361-
<pre class='lang-javascript'>
361+
<pre class=lang-javascript>
362362
if(obj.dispatchEvent(event)) {
363363
// event was not canceled, time for some magic
364364
&hellip;
365365
}
366366
</pre>
367367

368-
When an <a>event</a> is
369-
<a>dispatched</a> to an object that
370-
<a>participates</a> in a
371-
<a>tree</a> (e.g. an
372-
<a for="/">element</a>), it can reach
373-
<a>event listeners</a> on that object's
374-
<a>ancestors</a> too. First all object's
375-
<a>ancestor</a>
376-
<a>event listeners</a> whose
377-
<a for="event listener">capture</a> variable is set to true are invoked, in
378-
<a>tree order</a>. Second, object's own
379-
<a>event listeners</a> are invoked. And
380-
finally, and only if <a>event</a>'s
381-
{{Event/bubbles}} attribute value is true,
382-
object's <a>ancestor</a>
383-
<a>event listeners</a> are invoked again,
384-
but now in reverse <a>tree order</a>.
385-
386-
Let's look at an example of how <a>events</a> work in a <a>tree</a>:
387-
388-
<pre class='lang-markup'>
368+
<p>When an <a>event</a> is <a>dispatched</a> to an object that <a>participates</a> in a <a>tree</a>
369+
(e.g., an <a for=/>element</a>), it can reach <a>event listeners</a> on that object's
370+
<a>ancestors</a> too. Effectively, all the object's <a>inclusive ancestor</a> <a>event listeners</a>
371+
whose <a for="event listener">capture</a> is true are invoked, in <a>tree order</a>. And then, if
372+
<a>event</a>'s {{Event/bubbles}} is true, all the object's <a>inclusive ancestor</a>
373+
<a>event listeners</a> whose <a for="event listener">capture</a> is false are invoked, now in
374+
reverse <a>tree order</a>.
375+
376+
<p>Let's look at an example of how <a>events</a> work in a <a>tree</a>:
377+
378+
<pre class=lang-markup>
389379
&lt;!doctype html>
390380
&lt;html>
391381
&lt;head>
@@ -406,19 +396,13 @@ Let's look at an example of how <a>events</a> work in a <a>tree</a>:
406396
&lt;/html>
407397
</pre>
408398

409-
The <code>debug</code> function will be invoked twice. Each time the <a>event</a>'s
410-
{{Event/target}} attribute value will be the
411-
<code>span</code> <a for="/">element</a>. The
412-
first time {{Event/currentTarget}} attribute's
413-
value will be the <a>document</a>, the second
414-
time the <code>body</code> <a for="/">element</a>.
415-
{{Event/eventPhase}} attribute's value
416-
switches from {{Event/CAPTURING_PHASE}}
417-
to {{Event/BUBBLING_PHASE}}. If an
418-
<a>event listener</a> was registered for
419-
the <code>span</code> <a for="/">element</a>,
420-
{{Event/eventPhase}} attribute's value
421-
would have been {{Event/AT_TARGET}}.
399+
<p>The <code>debug</code> function will be invoked twice. Each time the <a>event</a>'s
400+
{{Event/target}} attribute value will be the <code>span</code> <a for=/>element</a>. The first time
401+
{{Event/currentTarget}} attribute's value will be the <a>document</a>, the second time the
402+
<code>body</code> <a for=/>element</a>. {{Event/eventPhase}} attribute's value switches from
403+
{{Event/CAPTURING_PHASE}} to {{Event/BUBBLING_PHASE}}. If an <a>event listener</a> was registered
404+
for the <code>span</code> <a for=/>element</a>, {{Event/eventPhase}} attribute's value would have
405+
been {{Event/AT_TARGET}}.
422406

423407

424408
<h3 id=interface-event>Interface {{Event}}</h3>
@@ -1959,7 +1943,7 @@ applications.
19591943

19601944
To illustrate, consider this HTML document:
19611945

1962-
<pre class='lang-markup'>
1946+
<pre class=lang-markup>
19631947
&lt;!DOCTYPE html>
19641948
&lt;html class=e>
19651949
&lt;head>&lt;title>Aliens?&lt;/title>&lt;/head>
@@ -4480,7 +4464,7 @@ when invoked, must run these steps:
44804464

44814465
<p class="note no-backref">Whether to return {{Node/DOCUMENT_POSITION_PRECEDING}} or
44824466
{{Node/DOCUMENT_POSITION_FOLLOWING}} is typically implemented via pointer comparison. In
4483-
JavaScript implementations a cached <code class='lang-javascript'>Math.random()</code> value can
4467+
JavaScript implementations a cached <code class=lang-javascript>Math.random()</code> value can
44844468
be used.
44854469

44864470
<li><p>If <var>node1</var> is an <a>ancestor</a> of <var>node2</var> and <var>attr1</var> is null,
@@ -5001,7 +4985,7 @@ method, when invoked, must return the
50014985
<a>list of elements with qualified name <var>qualifiedName</var></a> for <a>this</a>.
50024986

50034987
<p class="note no-backref">Thus, in an <a>HTML document</a>,
5004-
<code class='lang-javascript'>document.getElementsByTagName("FOO")</code> will match
4988+
<code class=lang-javascript>document.getElementsByTagName("FOO")</code> will match
50054989
<code>&lt;FOO></code> elements that are not in the
50064990
<a>HTML namespace</a>, and <code>&lt;foo></code> elements that are in
50074991
the <a>HTML namespace</a>, but not <code>&lt;FOO></code> elements
@@ -7464,9 +7448,9 @@ are <a>boundary points</a>. A <a>boundary point</a> is a <a for=/>tuple</a> cons
74647448
<ul class="domTree">
74657449
<li class="t1">{{Element}}: <code>p</code>
74667450
<ul>
7467-
<li class="t1">{{Element}}: <code class='lang-markup'>&lt;img src="insanity-wolf" alt="Little-endian BOM; decode as big-endian!"></code>
7451+
<li class="t1">{{Element}}: <code class=lang-markup>&lt;img src="insanity-wolf" alt="Little-endian BOM; decode as big-endian!"></code>
74687452
<li class="t3">{{Text}}: <span>&nbsp;CSS 2.1 syndata is&nbsp;</span>
7469-
<li class="t1">{{Element}}: <code class='lang-markup'>&lt;em></code>
7453+
<li class="t1">{{Element}}: <code class=lang-markup>&lt;em></code>
74707454
<ul>
74717455
<li class="t3">{{Text}}: <span>awesome</span>
74727456
</ul>
@@ -7482,7 +7466,7 @@ are <a>boundary points</a>. A <a>boundary point</a> is a <a for=/>tuple</a> cons
74827466
<var ignore>em</var> to the <code>em</code>
74837467
<a for="/">element</a>, this would be done as follows:
74847468

7485-
<pre class='lang-javascript'><code>
7469+
<pre class=lang-javascript><code>
74867470
var range = new Range(),
74877471
firstText = p.childNodes[1],
74887472
secondText = em.firstChild
@@ -10122,6 +10106,7 @@ Justin Summerlin,
1012210106
Kagami Sascha Rosylight,
1012310107
呂康豪 (Kang-Hao Lu),
1012410108
田村健人 (Kent TAMURA),
10109+
Kevin J. Sung,
1012510110
Kevin Sweeney,
1012610111
Kirill Topolyan,
1012710112
Koji Ishii,

0 commit comments

Comments
 (0)