@@ -66,7 +66,7 @@ argument occurs.
6666
6767{{index "addEventListener method", "event handling", "window object"}}
6868
69- Each ((browser)) event handler is registered in a context. In the last example we called
69+ Each ((browser)) event handler is registered in a context. In the previous example we called
7070` addEventListener ` on the ` window ` object to register a handler
7171for the whole window. Such a method can also be found on ((DOM))
7272elements and some other types of objects. Event listeners are
@@ -98,7 +98,7 @@ attribute whose name is the event name with `on` in front of it.
9898
9999But a node can have only one ` onclick ` attribute, so you can register
100100only one handler per node that way. The ` addEventListener ` method
101- allows you to add any number of handlers, so that it is safe to add
101+ allows you to add any number of handlers so that it is safe to add
102102handlers even if there is already another handler on the element.
103103
104104{{index "removeEventListener method"}}
@@ -120,7 +120,7 @@ The `removeEventListener` method, called with arguments similar to
120120
121121{{index [ function, "as value"] }}
122122
123- The function given to ` removeEventListener ` has to be the exact same
123+ The function given to ` removeEventListener ` has to be the same
124124function value that was given to ` addEventListener ` . So, to unregister
125125a handler, you'll want to give the function a name (` once ` , in the
126126example) to be able to pass the same function value to both methods.
@@ -288,8 +288,8 @@ tab ([control]{keyname}-W or [command]{keyname}-W) cannot be handled by JavaScri
288288
289289{{index keyboard, "keydown event", "keyup event", "event handling"}}
290290
291- When a key on the keyboard is pressed down , your browser fires a
292- ` "keydown" ` event. When it is released again , you get a ` "keyup" `
291+ When a key on the keyboard is pressed, your browser fires a
292+ ` "keydown" ` event. When it is released, you get a ` "keyup" `
293293event.
294294
295295``` {lang: "text/html", focus: true}
@@ -314,7 +314,7 @@ Despite its name, `"keydown"` fires not only when the key is
314314physically pushed down. When a key is pressed and held, the event
315315fires again every time the key _ repeats_ . Sometimes you have to be
316316careful about this. For example, if you add a button to the DOM when a
317- key is pressed down, and remove it again when the key is released, you
317+ key is pressed and remove it again when the key is released, you
318318might accidentally add hundreds of buttons when the key is held down
319319longer.
320320
@@ -323,9 +323,9 @@ longer.
323323The example looked at the ` key ` property of the event object to see
324324which key the event is about. This property holds a string that, for
325325most keys, corresponds to the thing that pressing that key would type.
326- For special keys like [ enter] {keyname}, it holds a string that names the key
326+ For special keys such as [ enter] {keyname}, it holds a string that names the key
327327(` "Enter" ` , in this case). If you hold [ shift] {keyname} while pressing a key,
328- that might also influence the name of the key—` "v" ` becomes ` "V" ` ,
328+ that might also influence the name of the key—` "v" ` becomes ` "V" ` , and
329329` "1" ` may become ` "!" ` , if that is what pressing [ shift] {keyname}-1 produces on
330330your keyboard.
331331
@@ -361,8 +361,8 @@ When the user is typing text, using key events to figure out what is
361361being typed is problematic. Some platforms, most notably the ((virtual
362362keyboard)) on ((Android)) ((phone))s, don't fire key events. But even
363363when you have an old-fashioned keyboard, some types of text input
364- don't match key presses in a straightforward way, such as (( IME))
365- ("Input Method Editor") software used by people whose scripts don't
364+ don't match key presses in a straightforward way, such as _ input method editor _ ((( IME) ))
365+ software used by people whose scripts don't
366366fit on a keyboard, where multiple key strokes are combined to create
367367characters.
368368
@@ -522,7 +522,7 @@ programming interface.
522522{{index touch, "mousedown event", "mouseup event", "click event"}}
523523
524524The style of graphical browser that we use was designed with mouse
525- interfaces in mind, at a time where touchscreens were very rare. To
525+ interfaces in mind, at a time where touchscreens were rare. To
526526make the Web "work" on early touchscreen phones, browsers for those
527527devices pretended, to a certain extent, that touch events were mouse
528528events. If you tap your screen, you'll get ` "mousedown" ` , ` "mouseup" ` ,
@@ -533,17 +533,17 @@ from a mouse: it doesn't have multiple buttons, you can't track the
533533finger when it isn't on the screen (to simulate ` "mousemove" ` ), and it
534534allows multiple fingers to be on the screen at the same time.
535535
536- Mouse events only cover touch interaction in straightforward cases—if
536+ Mouse events cover touch interaction only in straightforward cases—if
537537you add a ` "click" ` handler to a button, touch users will still be
538- able to use it. But something like the resizeable bar in the last
538+ able to use it. But something like the resizeable bar in the previous
539539example does not work on a touchscreen.
540540
541541{{index "touchstart event", "touchmove event", "touchend event"}}
542542
543543There are specific event types fired by touch interaction. When a
544544finger starts touching the screen, you get a ` "touchstart" ` event.
545- When it is moved while touching, ` "touchmove" ` events fire. And
546- finally , when it stops touching the screen, you'll see a ` "touchend" `
545+ When it is moved while touching, ` "touchmove" ` events fire.
546+ Finally , when it stops touching the screen, you'll see a ` "touchend" `
547547event.
548548
549549{{index "touches property", "clientX property", "clientY property", "pageX property", "pageY property"}}
@@ -585,7 +585,7 @@ touching finger:
585585
586586{{index "preventDefault method"}}
587587
588- You'll often want to call ` preventDefault ` in touch event handlers, to
588+ You'll often want to call ` preventDefault ` in touch event handlers to
589589override the browser's default behavior (which may include scrolling
590590the page on swiping) and to prevent the mouse events from being fired,
591591for which you may _ also_ have a handler.
@@ -641,7 +641,7 @@ is sized relative to the page width.
641641The global ` innerHeight ` binding gives us the height of the window,
642642which we have to subtract from the total scrollable height—you can't
643643keep scrolling when you hit the bottom of the document. There's also
644- an ` innerWidth ` , for the window width. By dividing ` pageYOffset ` , the
644+ an ` innerWidth ` for the window width. By dividing ` pageYOffset ` , the
645645current scroll position, by the maximum scroll position and
646646multiplying by 100, we get the percentage for the progress bar.
647647
@@ -691,7 +691,7 @@ currently has focus:
691691
692692{{if book
693693
694- In this screenshot, the help text for the age field is shown .
694+ This screenshot shows the help text for the age field.
695695
696696{{figure {url: "img/help-field.png", alt: "Providing help when a field is focused",width: "4.4cm"}}}
697697
@@ -743,7 +743,7 @@ forever and force them to look at dodgy weight-loss ads.
743743
744744In the context of the event loop, as discussed in [ Chapter ?] ( async ) ,
745745browser event handlers behave like other asynchronous notifications.
746- They are scheduled when the event occurs, but must wait for other
746+ They are scheduled when the event occurs but must wait for other
747747scripts that are running to finish before they get a chance to run.
748748
749749The fact that events can be processed only when nothing else is
@@ -761,7 +761,7 @@ that runs alongside the main script, on its own timeline.
761761Imagine that squaring a number is a heavy, long-running computation
762762that we want to perform in a separate ((thread)). We could write a
763763file called ` code/squareworker.js ` that responds to messages by
764- computing a square and sending a message back:
764+ computing a square and sending a message back.
765765
766766```
767767addEventListener("message", event => {
@@ -775,7 +775,7 @@ with the main script's environment. Instead, you have to communicate
775775with them by sending messages back and forth.
776776
777777This code spawns a worker running that script, sends it a few
778- messages, and outputs the responses:
778+ messages, and outputs the responses.
779779
780780``` {test: no}
781781let squareWorker = new Worker("code/squareworker.js");
@@ -801,7 +801,7 @@ receive a _copy_ of them, rather than the value itself.
801801{{index timeout, "setTimeout function"}}
802802
803803We saw the ` setTimeout ` function in [ Chapter ?] ( async ) . It schedules
804- another function to be called later, after a given amount of
804+ another function to be called later, after a given number of
805805milliseconds.
806806
807807{{index "clearTimeout function"}}
@@ -895,7 +895,7 @@ We can use a slightly different pattern if we want to space responses
895895so that they're separated by at least a certain length of ((time)) but
896896want to fire them _ during_ a series of events, not just afterward. For
897897example, we might want to respond to ` "mousemove" ` events by showing
898- the current coordinates of the mouse, but only every 250 milliseconds.
898+ the current coordinates of the mouse but only every 250 milliseconds.
899899
900900``` {lang: "text/html"}
901901<script>
@@ -956,7 +956,7 @@ You can control the size of text (emoji are text) by setting the
956956Remember to include a unit in the value—for example, pixels (` 10px ` ).
957957
958958The key names of the arrow keys are ` "ArrowUp" ` and ` "ArrowDown" ` .
959- Make sure the keys only change the balloon, without scrolling the
959+ Make sure the keys change only the balloon, without scrolling the
960960page.
961961
962962When that works, add a feature where, if you blow up the balloon past
@@ -984,7 +984,7 @@ You'll want to register a handler for the `"keydown"` event and look
984984at ` event.key ` to figure out whether the up or down arrow key was
985985pressed.
986986
987- The current size can be kept in a binding, so that you can base the
987+ The current size can be kept in a binding so that you can base the
988988new size on it. It'll be helpful to define a function that updates the
989989size—both the binding and the style of the balloon in the DOM—so that
990990you can call it from your event handler, and possibly also once when
@@ -1053,8 +1053,7 @@ if}}
10531053{{index "mouse trail (exercise)"}}
10541054
10551055Creating the elements is best done with a loop. Append them to the
1056- document to make them show up. To be able to access them later in
1057- order to change their position, you'll want to store the elements in
1056+ document to make them show up. To be able to access them later to change their position, you'll want to store the elements in
10581057an array.
10591058
10601059{{index "mousemove event", [ array, indexing] , "remainder operator", "% operator"}}
@@ -1097,7 +1096,7 @@ of the child. All but one of the original children should be hidden
10971096selected by clicking the buttons.
10981097
10991098When that works, extend it to style the button for the currently
1100- selected tab differently, so that it is obvious which tab is selected.
1099+ selected tab differently so that it is obvious which tab is selected.
11011100
11021101{{if interactive
11031102
@@ -1126,12 +1125,12 @@ node's `childNodes` property as a collection of tab nodes. For one
11261125thing, when you add the buttons, they will also become child nodes and
11271126end up in this object because it is a live data structure. For
11281127another, the text nodes created for the ((whitespace)) between the
1129- nodes are also in ` childNodes ` , but should not get their own tabs. You
1128+ nodes are also in ` childNodes ` but should not get their own tabs. You
11301129can use ` children ` instead of ` childNodes ` to ignore text nodes.
11311130
11321131{{index "TEXT_NODE code", "nodeType property"}}
11331132
1134- You could start by building up an array of tabs, so that you have easy
1133+ You could start by building up an array of tabs so that you have easy
11351134access to them. To implement the styling of the buttons, you could
11361135store objects that contain both the tab panel and its button.
11371136
@@ -1140,7 +1139,7 @@ either store the previously selected tab and change only the styles
11401139needed to hide that and show the new one, or you can just update the
11411140style of all tabs every time a new tab is selected.
11421141
1143- You might want to call this function immediately, to make the
1142+ You might want to call this function immediately to make the
11441143interface start with the first tab visible.
11451144
11461145hint}}
0 commit comments