Skip to content

Commit de351f6

Browse files
authored
Merge pull request #195 from JulianCDC/browser-default-actions
Browser default actions
2 parents cd4492b + a7dc50d commit de351f6

File tree

11 files changed

+126
-126
lines changed

11 files changed

+126
-126
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+
Lorsque le navigateur lit l'attribut `on*`, comme `onclick`, il créer le gestionnaire depuis son contenu.
22

3-
For `onclick="handler()"` the function will be:
3+
Pour `onclick="handler()"` la fonction sera:
44

55
```js
66
function(event) {
7-
handler() // the content of onclick
7+
handler() // le contenu de 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+
Maintenant nous pouvons voir que la valeur retournée par `handler()` n'est pas utilisée et n'affecte pas le résultat.
1212

13-
The fix is simple:
13+
La correction est simple:
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+
Nous pouvons aussi utiliser `event.preventDefault()`, comme ceci:
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+
# Pourquoi "return false" ne fonctionne pas?
66

7-
Why in the code below `return false` doesn't work at all?
7+
Pourquoi dans le code ci-dessous `return false` ne fonctionne pas?
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()">le navigateur va aller sur w3.org</a>
1818
```
1919

20-
The browser follows the URL on click, but we don't want it.
20+
Le navigateur suit le lien lors du clic, mais nous ne voulons pas ça.
2121

22-
How to fix?
22+
Comment réparer ce problème?
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+
C'est une bonne utilisation de la délégation d'évènement.
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+
Dans la vie réelle au lieu de demander nous pouvons envoyer une requête de "logging" au serveur pour sauvegarder les informations sur où l'utilisateur a quitté. Ou nous pouvons charger le contenu et l'afficher directement dans la page (si permis).
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+
Tout ce que nous avons à faire est de capturer le `contents.onclick` et utiliser `confirm` pour demander à l'utilisateur. Une bonne idée serait d'utiliser `link.getAttribute('href')` plutôt que `link.href` pour l'URL. Regardez la solution pour plus de détails.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
contents.onclick = function(event) {
2525

2626
function handleLink(href) {
27-
let isLeaving = confirm(`Leave for ${href}?`);
27+
let isLeaving = confirm(`Quitter pour ${href}?`);
2828
if (!isLeaving) return false;
2929
}
3030

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+
# Capturer des liens dans l'élément
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+
Faire en sorte que tous les liens dans l'élément avec `id="contents"` demande à l'utilisateur s'il veut vraiment partir. Et s'il ne veut pas ne suivez pas le lien.
88

9-
Like this:
9+
Commce ceci:
1010

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

13-
Details:
13+
Détails:
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+
- Le HTML à l'intérieur de l'élément peut être chargé ou regénéré dynamiquement à n'importe quel moment, donc nous ne pouvons pas trouver tous les liens et mettre des gestionnaires dessus. Utilisez la délégation d'évènement.
16+
- Le contenu peut avoir des éléments imbriqués. À l'intérieur des liens aussi, comme ceci `<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+
La solution est d'assigner le gestionnaire au conteneur et suivre les clics. Si un clic est sur le lien `<a>`, alors changer `src` de `#largeImg` pour le `href` de la miniature.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
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+
<!-- le navigateur affiche une petite infobulle lors du survol avec le texte de l'attribut "title" -->
1616
<li>
1717
<a href="https://en.js.cx/gallery/img2-lg.jpg" title="Image 2"><img src="https://en.js.cx/gallery/img2-thumb.jpg"></a>
1818
</li>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
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+
<!-- le navigateur affiche une petite infobulle lors du survol avec le texte de l'attribut "title" -->
1616
<li>
1717
<a href="https://en.js.cx/gallery/img2-lg.jpg" title="Image 2"><img src="https://en.js.cx/gallery/img2-thumb.jpg"></a>
1818
</li>

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+
# Galerie d'images
66

7-
Create an image gallery where the main image changes by the click on a thumbnail.
7+
Créer une galerie d'images dans laquelle l'image principale change lors d'un clic sur une miniature.
88

9-
Like this:
9+
Comme ceci:
1010

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

13-
P.S. Use event delegation.
13+
P.S. Utilisez la délégation d'évènement.

0 commit comments

Comments
 (0)