Skip to content

Commit c401715

Browse files
Browser default actions (#264)
1 parent 0f70f7d commit c401715

File tree

12 files changed

+140
-140
lines changed

12 files changed

+140
-140
lines changed

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="https://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="https://w3.org" onclick="handler()">the browser will go to w3.org</a>
17+
<a href="https://w3.org" onclick="handler()">браузер перейде на w3.org</a>
1818
```
1919

20-
The browser follows the URL on click, but we don't want it.
20+
Браузер переходить за URL-адресою після кліку, але нам це не потрібно.
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+
У реальному житті замість того, щоб запитувати, ми можемо надіслати запит на «реєстрацію» на сервер, який зберігає інформацію про те, куди пішов відвідувач. Або ми можемо завантажити вміст і показати його прямо на сторінці (якщо це дозволено).
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` для URL-адреси. Подробиці дивіться у рішенні.

2-ui/2-events/04-default-browser-action/2-catch-link-navigation/solution.view/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
<fieldset id="contents">
1717
<legend>#contents</legend>
1818
<p>
19-
How about to read <a href="https://wikipedia.org">Wikipedia</a> or visit <a href="https://w3.org"><i>W3.org</i></a> and learn about modern standards?
19+
Як щодо того, щоб почитати <a href="https://wikipedia.org">Вікіпедію</a> або відвідати <a href="https://w3.org"><i>W3.org</i></a> і дізнатися про сучасні стандарти?
2020
</p>
2121
</fieldset>
2222

2323
<script>
2424
contents.onclick = function(event) {
2525

2626
function handleLink(href) {
27-
let isLeaving = confirm(`Leave for ${href}?`);
27+
let isLeaving = confirm(`Перейти на ${href}?`);
2828
if (!isLeaving) return false;
2929
}
3030

2-ui/2-events/04-default-browser-action/2-catch-link-navigation/source.view/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<fieldset id="contents">
1717
<legend>#contents</legend>
1818
<p>
19-
How about to read <a href="https://wikipedia.org">Wikipedia</a> or visit <a href="https://w3.org"><i>W3.org</i></a> and learn about modern standards?
19+
Як щодо того, щоб почитати <a href="https://wikipedia.org">Вікіпедію</a> або відвідати <a href="https://w3.org"><i>W3.org</i></a> і дізнатися про сучасні стандарти?
2020
</p>
2121
</fieldset>
2222

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 event delegation.
16-
- The content may have nested tags. Inside links too, like `<a href=".."><i>...</i></a>`.
15+
- HTML всередині елемента може бути завантажений або динамічно відновлений в будь-який час, тому ми не можемо знайти всі посилання та розмістити на них обробники. Використовуйте делегування подій.
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+
Рішення полягає в тому, щоб призначити обробник контейнеру та відстежувати кліки. Якщо клік відбувається на посилання `<a>`, змініть `src` для `#largeImg` на `href` мініатюри.

2-ui/2-events/04-default-browser-action/3-image-gallery/solution.view/index.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33

44
<head>
5-
<title>Gallery</title>
5+
<title>Галерея</title>
66
<link rel="stylesheet" href="gallery.css">
77
<meta charset="utf-8">
88
</head>
@@ -12,21 +12,21 @@
1212
<p><img id="largeImg" src="https://en.js.cx/gallery/img1-lg.jpg" alt="Large image"></p>
1313

1414
<ul id="thumbs">
15-
<!-- the browser shows a small built-in tooltip on hover with the text from "title" attribute -->
15+
<!-- браузер показує невелику вбудовану підказку при наведенні курсора з текстом атрибута "title" -->
1616
<li>
17-
<a href="https://en.js.cx/gallery/img2-lg.jpg" title="Image 2"><img src="https://en.js.cx/gallery/img2-thumb.jpg"></a>
17+
<a href="https://en.js.cx/gallery/img2-lg.jpg" title="Зображення 2"><img src="https://en.js.cx/gallery/img2-thumb.jpg"></a>
1818
</li>
1919
<li>
20-
<a href="https://en.js.cx/gallery/img3-lg.jpg" title="Image 3"><img src="https://en.js.cx/gallery/img3-thumb.jpg"></a>
20+
<a href="https://en.js.cx/gallery/img3-lg.jpg" title="Зображення 3"><img src="https://en.js.cx/gallery/img3-thumb.jpg"></a>
2121
</li>
2222
<li>
23-
<a href="https://en.js.cx/gallery/img4-lg.jpg" title="Image 4"><img src="https://en.js.cx/gallery/img4-thumb.jpg"></a>
23+
<a href="https://en.js.cx/gallery/img4-lg.jpg" title="Зображення 4"><img src="https://en.js.cx/gallery/img4-thumb.jpg"></a>
2424
</li>
2525
<li>
26-
<a href="https://en.js.cx/gallery/img5-lg.jpg" title="Image 5"><img src="https://en.js.cx/gallery/img5-thumb.jpg"></a>
26+
<a href="https://en.js.cx/gallery/img5-lg.jpg" title="Зображення 5"><img src="https://en.js.cx/gallery/img5-thumb.jpg"></a>
2727
</li>
2828
<li>
29-
<a href="https://en.js.cx/gallery/img6-lg.jpg" title="Image 6"><img src="https://en.js.cx/gallery/img6-thumb.jpg"></a>
29+
<a href="https://en.js.cx/gallery/img6-lg.jpg" title="Зображення 6"><img src="https://en.js.cx/gallery/img6-thumb.jpg"></a>
3030
</li>
3131
</ul>
3232

2-ui/2-events/04-default-browser-action/3-image-gallery/source.view/index.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33

44
<head>
5-
<title>Gallery</title>
5+
<title>Галерея</title>
66
<link rel="stylesheet" href="gallery.css">
77
<meta charset="utf-8">
88
</head>
@@ -12,21 +12,21 @@
1212
<p><img id="largeImg" src="https://en.js.cx/gallery/img1-lg.jpg" alt="Large image"></p>
1313

1414
<ul id="thumbs">
15-
<!-- the browser shows a small built-in tooltip on hover with the text from "title" attribute -->
15+
<!-- браузер показує невелику вбудовану підказку при наведенні курсора з текстом атрибута "title" -->
1616
<li>
17-
<a href="https://en.js.cx/gallery/img2-lg.jpg" title="Image 2"><img src="https://en.js.cx/gallery/img2-thumb.jpg"></a>
17+
<a href="https://en.js.cx/gallery/img2-lg.jpg" title="Зображення 2"><img src="https://en.js.cx/gallery/img2-thumb.jpg"></a>
1818
</li>
1919
<li>
20-
<a href="https://en.js.cx/gallery/img3-lg.jpg" title="Image 3"><img src="https://en.js.cx/gallery/img3-thumb.jpg"></a>
20+
<a href="https://en.js.cx/gallery/img3-lg.jpg" title="Зображення 3"><img src="https://en.js.cx/gallery/img3-thumb.jpg"></a>
2121
</li>
2222
<li>
23-
<a href="https://en.js.cx/gallery/img4-lg.jpg" title="Image 4"><img src="https://en.js.cx/gallery/img4-thumb.jpg"></a>
23+
<a href="https://en.js.cx/gallery/img4-lg.jpg" title="Зображення 4"><img src="https://en.js.cx/gallery/img4-thumb.jpg"></a>
2424
</li>
2525
<li>
26-
<a href="https://en.js.cx/gallery/img5-lg.jpg" title="Image 5"><img src="https://en.js.cx/gallery/img5-thumb.jpg"></a>
26+
<a href="https://en.js.cx/gallery/img5-lg.jpg" title="Зображення 5"><img src="https://en.js.cx/gallery/img5-thumb.jpg"></a>
2727
</li>
2828
<li>
29-
<a href="https://en.js.cx/gallery/img6-lg.jpg" title="Image 6"><img src="https://en.js.cx/gallery/img6-thumb.jpg"></a>
29+
<a href="https://en.js.cx/gallery/img6-lg.jpg" title="Зображення 6"><img src="https://en.js.cx/gallery/img6-thumb.jpg"></a>
3030
</li>
3131
</ul>
3232

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)