You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 497c9fd
Browse filesBrowse the repository at this point in the historyBrowse files
В строке `(*)` используется атрибут, а не свойство `href`, чтобы показать в `confirm` именно то, что написано в HTML-атрибуте, так как свойство может отличаться, оно обязано содержать полный валидный адрес.
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).
28
4
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.
Copy file name to clipboardExpand all lines: 2-ui/2-events/7-default-browser-action/2-catch-link-navigation/solution.view/index.html
+9-12Lines changed: 9 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -16,28 +16,25 @@
16
16
<fieldsetid="contents">
17
17
<legend>#contents</legend>
18
18
<p>
19
-
Как насчет почитать <ahref="http://wikipedia.org">Википедию</a>, или посетить<ahref="http://w3.org"><i>W3.org</i></a>и узнать про современные стандарты?
19
+
How about to read <ahref="http://wikipedia.org">Wikipedia</a> or visit<ahref="http://w3.org"><i>W3.org</i></a>and learn about modern standards?
Copy file name to clipboardExpand all lines: 2-ui/2-events/7-default-browser-action/2-catch-link-navigation/source.view/index.html
+2-3Lines changed: 2 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -16,10 +16,9 @@
16
16
<fieldsetid="contents">
17
17
<legend>#contents</legend>
18
18
<p>
19
-
Как насчет почитать <ahref="http://wikipedia.org">Википедию</a>, или посетить<ahref="http://w3.org"><i>W3.org</i></a>и узнать про современные стандарты?
19
+
How about to read <ahref="http://wikipedia.org">Wikipedia</a> or visit<ahref="http://w3.org"><i>W3.org</i></a>and learn about modern standards?
Copy file name to clipboardExpand all lines: 2-ui/2-events/7-default-browser-action/2-catch-link-navigation/task.md
+6-7Lines changed: 6 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,16 +2,15 @@ importance: 5
2
2
3
3
---
4
4
5
-
# Поймайте переход по ссылке
5
+
# Catch links in the element
6
6
7
-
Сделайте так, чтобы при клике на ссылки внутри элемента `#contents` пользователю выводился вопрос о том, действительно ли он хочет покинуть страницу и если он не хочет, то прерывать переход по ссылке.
7
+
Make all links inside the element with `id="contents"` ask the user if he really wants to leave. And if he doesn't then don't follow.
8
8
9
-
Так это должно работать:
9
+
Like this:
10
10
11
11
[iframe height=100 border=1 src="solution"]
12
12
13
-
Детали:
14
-
15
-
- Содержимое `#contents` может быть загружено динамически и присвоено при помощи `innerHTML`. Так что найти все ссылки и поставить на них обработчики нельзя. Используйте делегирование.
16
-
- Содержимое может содержать вложенные теги, *в том числе внутри ссылок*, например, `<a href=".."><i>...</i></a>`.
13
+
Details:
17
14
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>`.
Для того, чтобы картинка загрузилась, достаточно создать новый элемент `IMG` и указать ему `src`, вот так:
34
-
35
-
```js
36
-
var imgs =thumbs.getElementsByTagName('img');
37
-
for (var i =0; i <imgs.length; i++) {
38
-
var url = imgs[i].parentNode.href;
39
-
40
-
*!*
41
-
var img =document.createElement('img');
42
-
img.src= url;
43
-
*/!*
44
-
}
45
-
```
46
-
47
-
Как только элемент создан и ему назначен `src`, браузер сам начинает скачивать файл картинки.
48
-
49
-
При правильных настройках сервера как-то использовать этот элемент не обязательно -- картинка уже закеширована.
50
-
51
-
**Семантичная верстка**
52
-
53
-
Для списка картинок используется `DIV`. С точки зрения семантики более верный вариант -- список `UL/LI`.
54
-
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.
Copy file name to clipboardExpand all lines: 2-ui/2-events/7-default-browser-action/3-image-gallery/task.md
+4-11Lines changed: 4 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,19 +2,12 @@ importance: 5
2
2
3
3
---
4
4
5
-
# Галерея изображений
5
+
# Image gallery
6
6
7
-
Создайте галерею изображений, в которой основное изображение изменяется при клике на уменьшенный вариант.
7
+
Create an image gallery where the main image changes by the click on a thumbnail.
8
8
9
-
Результат должен выглядеть так:
9
+
Like this:
10
10
11
11
[iframe src="solution" height=600]
12
12
13
-
Для обработки событий используйте делегирование, т.е. не более одного обработчика.
14
-
15
-
P.S. Обратите внимание -- клик может быть как на маленьком изображении `IMG`, так и на `A` вне него. При этом `event.target` будет, соответственно, либо `IMG`, либо `A`.
16
-
17
-
Дополнительно:
18
-
19
-
- Если получится -- сделайте предзагрузку больших изображений, чтобы при клике они появлялись сразу.
20
-
- Всё ли в порядке с семантической вёрсткой в HTML исходного документа? Если нет -- поправьте, чтобы было, как нужно.
0 commit comments