Skip to content

Commit 6ee7f83

Browse files
committed
wip(2-ui/2-events/04-default-browser-action): Перевести главу
1 parent c3913f5 commit 6ee7f83

7 files changed

Lines changed: 122 additions & 122 deletions

File tree

2-ui/2-events/04-default-browser-action/1-why-return-false-fails/solution.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
When the browser reads the `on*` attribute like `onclick`, it creates the handler from its content.
1+
Когда браузер считывает атрибут `on*`, например `onclick`, он создаёт обработчик как функцию с заданным телом.
22

3-
For `onclick="handler()"` the function will be:
3+
Фунция для `onclick="handler()"` будет:
44

55
```js
66
function(event) {
7-
handler() // the content of onclick
7+
handler() // содержимое onclick
88
}
99
```
1010

11-
Now we can see that the value returned by `handler()` is not used and does not affect the result.
11+
Сейчас нам видно, что возвращаемое значение `handler()` не используется и не влияет на результат.
1212

13-
The fix is simple:
13+
Исправить очень просто:
1414

1515
```html run
1616
<script>
@@ -23,7 +23,7 @@ The fix is simple:
2323
<a href="http://w3.org" onclick="*!*return handler()*/!*">w3.org</a>
2424
```
2525

26-
Also we can use `event.preventDefault()`, like this:
26+
Также мы можем использовать `event.preventDefault()`, например:
2727

2828
```html run
2929
<script>

2-ui/2-events/04-default-browser-action/1-why-return-false-fails/task.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 3
22

33
---
44

5-
# Why "return false" doesn't work?
5+
# Почему не работает return false?
66

7-
Why in the code below `return false` doesn't work at all?
7+
Почему в этом документе `return false` не работает?
88

99
```html autorun run
1010
<script>
@@ -14,9 +14,9 @@ Why in the code below `return false` doesn't work at all?
1414
}
1515
</script>
1616

17-
<a href="http://w3.org" onclick="handler()">the browser will go to w3.org</a>
17+
<a href="http://w3.org" onclick="handler()">w3.org</a>
1818
```
1919

20-
The browser follows the URL on click, but we don't want it.
20+
Браузер переходит по указанной ссылке, но нам этого не нужно.
2121

22-
How to fix?
22+
Как поправить?
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
That's a great use of the event delegation pattern.
1+
Это – классическая задача на тему делегирования.
22

3-
In real life instead of asking we can send a "logging" request to the server that saves the information about where the visitor left. Or we can load the content and show it right in the page (if allowable).
3+
В реальной жизни, мы можем перехватить событие и создать AJAX-запрос к серверу, который сохранит информацию о том, по какой ссылке ушел посетитель. Или мы можем загрузить содержимое и отобразить его прямо на странице (если допустимо).
44

5-
All we need is to catch the `contents.onclick` and use `confirm` to ask the user. A good idea would be to use `link.getAttribute('href')` instead of `link.href` for the URL. See the solution for details.
5+
Всё, что нам необходимо это поймать событие `contents.onclick` и использовать функцию `confirm`, чтобы задать вопрос пользователю. Хорошей идеей было бы использовать `link.getAttribute('href')` вместо `link.href` для ссылок. Смотрите решение в песочнице.

2-ui/2-events/04-default-browser-action/2-catch-link-navigation/task.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ importance: 5
22

33
---
44

5-
# Catch links in the element
5+
# Поймайте переход по ссылке
66

7-
Make all links inside the element with `id="contents"` ask the user if they really want to leave. And if they don't then don't follow.
7+
Сделайте так, чтобы при клике на ссылки внутри элемента `id="contents"` пользователю выводился вопрос о том, действительно ли он хочет покинуть страницу и если он не хочет, то прерывать переход по ссылке.
88

9-
Like this:
9+
Так это должно работать:
1010

1111
[iframe height=100 border=1 src="solution"]
1212

13-
Details:
13+
Детали:
1414

15-
- HTML inside the element may be loaded or regenerated dynamically at any time, so we can't find all links and put handlers on them. Use the event delegation.
16-
- The content may have nested tags. Inside links too, like `<a href=".."><i>...</i></a>`.
15+
- Содержимое `#contents` может быть загружено динамически и присвоено при помощи `innerHTML`. Так что найти все ссылки и поставить на них обработчики нельзя. Используйте делегирование.
16+
- Содержимое может содержать вложенные теги, *в том числе внутри ссылок*, например, `<a href=".."><i>...</i></a>`.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
The solution is to assign the handler to the container and track clicks. If a click is on the `<a>` link, then change `src` of `#largeImg` to the `href` of the thumbnail.
1+
Решение состоит в том, чтобы добавить обработчик на контейнер `#thumbs` и отслеживать клики на ссылках. Если клик происходит по ссылке `<a>`, тогда меняем атрибут `src` элемента `#largeImg` на `href` уменьшенного изображения.

2-ui/2-events/04-default-browser-action/3-image-gallery/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ importance: 5
22

33
---
44

5-
# Image gallery
5+
# Галерея изображений
66

7-
Create an image gallery where the main image changes by the click on a thumbnail.
7+
Создайте галерею изображений, в которой основное изображение изменяется при клике на уменьшенный вариант.
88

9-
Like this:
9+
Например:
1010

1111
[iframe src="solution" height=600]
1212

13-
P.S. Use event delegation.
13+
P.S. Применяйте делегирование.

0 commit comments

Comments
 (0)