minor
This commit is contained in:
parent
db0407b9f6
commit
c3fadb7dc1
3 changed files with 4 additions and 4 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
We can not only assign handlers, but also generate events from JavaScript.
|
||||
|
||||
Custom events can be used to create "graphical components". For instance, a root element of our own JS-based menu may trigger events telling what happens with the menu: `open` (menu open), `select` (an item is selected) and so on. Another code may listen to the events and observe what's happening with the menu.
|
||||
Custom events can be used to create "graphical components". For instance, a root element of our own JS-based menu may trigger events telling what happens with the menu: `open` (menu open), `select` (an item is selected) and so on. Another code may listen for the events and observe what's happening with the menu.
|
||||
|
||||
We can generate not only completely new events, that we invent for our own purposes, but also built-in ones, such as `click`, `mousedown` etc. That may be helpful for automated testing.
|
||||
|
||||
|
@ -174,7 +174,7 @@ Let's see a practical example - a hiding rabbit (could be a closing menu or some
|
|||
|
||||
Below you can see a `#rabbit` and `hide()` function that dispatches `"hide"` event on it, to let all interested parties know that the rabbit is going to hide.
|
||||
|
||||
Any handler can listen to that event with `rabbit.addEventListener('hide',...)` and, if needed, cancel the action using `event.preventDefault()`. Then the rabbit won't disappear:
|
||||
Any handler can listen for that event with `rabbit.addEventListener('hide',...)` and, if needed, cancel the action using `event.preventDefault()`. Then the rabbit won't disappear:
|
||||
|
||||
```html run refresh autorun
|
||||
<pre id="rabbit">
|
||||
|
|
|
@ -11,7 +11,7 @@ The first idea can be: run a function every `100ms` and measure the distance bet
|
|||
|
||||
Unfortunately, there's no way to get "current mouse coordinates" in JavaScript. There's no function like `getCurrentMouseCoordinates()`.
|
||||
|
||||
The only way to get coordinates is to listen to mouse events, like `mousemove`, and take coordinates from the event object.
|
||||
The only way to get coordinates is to listen for mouse events, like `mousemove`, and take coordinates from the event object.
|
||||
|
||||
So let's set a handler on `mousemove` to track coordinates and remember them. And then compare them, once per `100ms`.
|
||||
|
||||
|
|
|
@ -159,7 +159,7 @@ Details may vary depending on the browser, but the idea is same: any information
|
|||
|
||||
Why do we need error details?
|
||||
|
||||
There are many services (and we can build our own) that listen to global errors using `window.onerror`, save errors and provide an interface to access and analyze them. That's great, as we can see real errors, triggered by our users. But if a script comes from another origin, then there's no much information about errors in it, as we've just seen.
|
||||
There are many services (and we can build our own) that listen for global errors using `window.onerror`, save errors and provide an interface to access and analyze them. That's great, as we can see real errors, triggered by our users. But if a script comes from another origin, then there's no much information about errors in it, as we've just seen.
|
||||
|
||||
Similar cross-origin policy (CORS) is enforced for other types of resources as well.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue