@@ -108,7 +108,7 @@ handler.
108
108
----
109
109
110
110
(((function,as value)))To be able to unregister a handler function, we
111
- give it a name (like `once` in the previous example ) so that we
111
+ give it a name (such as `once`) so that we
112
112
can pass it to both `addEventListener` and `removeEventListener`.
113
113
114
114
== Event objects ==
@@ -250,7 +250,7 @@ they expect is broken.
250
250
251
251
Depending on the browser, some events can't be intercepted. On
252
252
Chrome, for example, ((keyboard)) shortcuts to close the current tab
253
- (Control -W or Command-W) cannot be handled by JavaScript.
253
+ (Ctrl -W or Command-W) cannot be handled by JavaScript.
254
254
255
255
== Key events ==
256
256
@@ -312,7 +312,7 @@ interested in.
312
312
(((modifier key)))(((shift key)))(((control key)))(((alt key)))(((meta
313
313
key)))(((command key)))(((ctrlKey property)))(((shiftKey
314
314
property)))(((altKey property)))(((metaKey property)))Modifier keys
315
- such as Shift, Control , Alt, and Meta (Command on Mac) generate key
315
+ such as Shift, Ctrl , Alt, and Meta (Command on Mac) generate key
316
316
events just like normal keys. But when looking for key combinations,
317
317
you can also find out whether these keys are held down by looking
318
318
at the `shiftKey`, `ctrlKey`, `altKey`, and `metaKey` properties of
@@ -321,7 +321,7 @@ keyboard and mouse events.
321
321
[source,text/html]
322
322
[focus="yes"]
323
323
----
324
- <p>Press Control -Space to continue.</p>
324
+ <p>Press Ctrl -Space to continue.</p>
325
325
<script>
326
326
addEventListener("keydown", function(event) {
327
327
if (event.keyCode == 32 && event.ctrlKey)
@@ -470,6 +470,8 @@ on this bar makes it narrower or wider:
470
470
471
471
ifdef::book_target[]
472
472
473
+ The resulting page looks like this:
474
+
473
475
image::img/drag-bar.png[alt="A draggable bar",width="5.3cm"]
474
476
475
477
endif::book_target[]
@@ -643,6 +645,9 @@ focus:
643
645
644
646
ifdef::book_target[]
645
647
648
+ The following screenshot shows the help text for the age field being
649
+ shown.
650
+
646
651
image::img/help-field.png[alt="Providing help when a field is focused",width="4.4cm"]
647
652
648
653
endif::book_target[]
@@ -676,7 +681,7 @@ might expect, done with the `preventDefault` method. Instead, it is
676
681
done by returning a string from the handler. The string will be used
677
682
in a dialog that asks the user if they want to stay on the page or
678
683
leave it. This mechanism ensures that a user is able to leave the
679
- page, even if it running a ((malicious script)) that would prefer to
684
+ page, even if it is running a ((malicious script)) that would prefer to
680
685
keep them there forever in order to force them to look at dodgy
681
686
weight loss ads.
682
687
@@ -777,7 +782,7 @@ var bombTimer = setTimeout(function() {
777
782
console.log("BOOM!");
778
783
}, 500);
779
784
780
- if (Math.random() < .5) { // 50% chance
785
+ if (Math.random() < 0 .5) { // 50% chance
781
786
console.log("Defused.");
782
787
clearTimeout(bombTimer);
783
788
}
@@ -813,7 +818,7 @@ event)))(((blocking)))Some types of events have the potential to fire
813
818
rapidly, many times in a row (the `"mousemove"` and `"scroll"` events,
814
819
for example). When handling such events, you must be careful not to do
815
820
anything too time-consuming or your handler will take up so much time
816
- that interaction with the document will start to feel slow and choppy.
821
+ that interaction with the document starts to feel slow and choppy.
817
822
818
823
(((setTimeout function)))If you do need to do something nontrivial in
819
824
such a handler, you can use `setTimeout` to make sure you are not
@@ -825,7 +830,7 @@ event)))In the first example, we want to do something when the user
825
830
has typed something, but we don't want to do it immediately for every
826
831
key event. When they are ((typing)) quickly, we just want to wait
827
832
until a pause occurs. Instead of immediately performing an action in
828
- the event handler, we can set a timeout instead. We also clear the
833
+ the event handler, we set a timeout instead. We also clear the
829
834
previous timeout (if any) so that when events occur close together
830
835
(closer than our timeout delay), the timeout from the previous event
831
836
will be canceled.
@@ -885,7 +890,7 @@ Event handlers make it possible to detect and react to events we have
885
890
no direct control over. The `addEventListener` method is used to
886
891
register such a handler.
887
892
888
- Each event has a name (`"keydown"`, `"focus"`, and so on) that identifies
893
+ Each event has a type (`"keydown"`, `"focus"`, and so on) that identifies
889
894
it. Most events are called on a specific DOM elements and then
890
895
_propagate_ to that element's ancestors, allowing handlers associated
891
896
with those elements to handle them.
@@ -978,7 +983,7 @@ follow the mouse pointer as you moved it across the page.
978
983
want you to implement a mouse trail. Use absolutely positioned `<div>`
979
984
elements with a fixed size and background color (refer to the
980
985
link:14_event.html#mouse_drawing[code] in the “Mouse Clicks”
981
- section for an example). Create 12 such elements, and when the
986
+ section for an example). Create a bunch of such elements and, when the
982
987
mouse moves, display them in the wake of the mouse pointer, somehow.
983
988
984
989
(((mousemove event)))There are various possible approaches here. You
@@ -1041,13 +1046,13 @@ to you.
1041
1046
=== Tabs ===
1042
1047
1043
1048
(((tabbed interface (exercise))))A tabbed interface is a common design
1044
- pattern. It allows you to select an interface panel by selecting from
1049
+ pattern. It allows you to select an interface panel by choosing from
1045
1050
a number of tabs “sticking out” above an element.
1046
1051
1047
1052
(((button (HTML tag))))(((display (CSS))))(((hidden element)))(((data
1048
1053
attribute)))In this exercise you'll implement a simple tabbed
1049
1054
interface. Write a function, `asTabs`, that takes a DOM node and
1050
- creates a tabbed interface showing the children of that node. It
1055
+ creates a tabbed interface showing the child elements of that node. It
1051
1056
should insert a list of `<button>` elements at the top of the node,
1052
1057
one for each child element, containing text retrieved from the
1053
1058
`data-tabname` attribute of the child. All but one of the original
0 commit comments