Skip to content

Commit a5d87fc

Browse files
committed
Browser default actions
1 parent fda8501 commit a5d87fc

File tree

12 files changed

+138
-138
lines changed

12 files changed

+138
-138
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+
Cuando el navegador lee el atributo `on*` como `onclick`, crea el controlador a partir de su contenido.
22

3-
For `onclick="handler()"` the function will be:
3+
Para `onclick="handler()"` la función será:
44

55
```js
66
function(event) {
7-
handler() // the content of onclick
7+
handler() // el contenido 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+
Ahora podemos ver que el valor devuelto por `handler()` no se usa y no afecta el resultado.
1212

13-
The fix is simple:
13+
La solución es 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+
También podemos usar `event.preventDefault()`, así:
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+
# ¿Por qué "return false" no funciona?
66

7-
Why in the code below `return false` doesn't work at all?
7+
¿Por qué en el código de abajo `return false` no funciona en absoluto?
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()">el navegador irá a w3.org</a>
1818
```
1919

20-
The browser follows the URL on click, but we don't want it.
20+
El navegador sigue la URL al hacer clic, pero no la queremos.
2121

22-
How to fix?
22+
¿Como se arregla?
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+
Ese es un gran uso del patrón de delegación de eventos.
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+
En la vida real, en lugar de preguntar, podemos enviar una solicitud de "logging" al servidor que guarda la información sobre dónde se fue el visitante. O podemos cargar el contenido y mostrarlo directamente en la página (si está permitido).
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+
Todo lo que necesitamos es capturar el `contents.onclick` y usar `confirm` para preguntar al usuario. Una buena idea sería usar `link.getAttribute('href')` en lugar de `link.href` para la URL. Consulte la solución para obtener más detalles.

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+
¿Que tal si leemos <a href="https://wikipedia.org">Wikipedia</a> o visitamos <a href="https://w3.org"><i>W3.org</i></a> y aprendemos sobre los estándares modernos?
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(`¿Irse a ${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+
¿Que tal si leemos <a href="https://wikipedia.org">Wikipedia</a> o visitamos <a href="https://w3.org"><i>W3.org</i></a> y aprendemos sobre los estándares modernos?
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+
# Captura enlaces en el elemento
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+
Haz que todos los enlaces dentro del elemento con `id="contents"` pregunten al usuario si realmente quiere irse. Y si no lo hacen, no sigas.
88

9-
Like this:
9+
Así:
1010

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

13-
Details:
13+
Detalles:
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+
- El HTML dentro del elemento puede cargarse o regenerarse dinámicamente en cualquier momento, por lo que no podemos encontrar todos los enlaces y ponerles controladores. Utilice la delegación de eventos.
16+
- El contenido puede tener etiquetas anidadas. Dentro de los enlaces también, como `<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 solución es asignar el controlador al contenedor y realizar un seguimiento de los clics. Si haces clic en el enlace `<a>`, cambias `src` de `#largeImg` por el `href` de la miniatura.

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@
99

1010
<body>
1111

12-
<p><img id="largeImg" src="https://en.js.cx/gallery/img1-lg.jpg" alt="Large image"></p>
12+
<p><img id="largeImg" src="https://es.js.cx/gallery/img1-lg.jpg" alt="Large image"></p>
1313

1414
<ul id="thumbs">
1515
<!-- the browser shows a small built-in tooltip on hover with the text from "title" attribute -->
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://es.js.cx/gallery/img2-lg.jpg" title="Image 2"><img src="https://es.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://es.js.cx/gallery/img3-lg.jpg" title="Image 3"><img src="https://es.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://es.js.cx/gallery/img4-lg.jpg" title="Image 4"><img src="https://es.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://es.js.cx/gallery/img5-lg.jpg" title="Image 5"><img src="https://es.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://es.js.cx/gallery/img6-lg.jpg" title="Image 6"><img src="https://es.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
@@ -9,24 +9,24 @@
99

1010
<body>
1111

12-
<p><img id="largeImg" src="https://en.js.cx/gallery/img1-lg.jpg" alt="Large image"></p>
12+
<p><img id="largeImg" src="https://es.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+
<!-- el navegador muestra un tooltip(ya viene integrado) con el texto del atributo "title" al pasar el ratón sobre él -->
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://es.js.cx/gallery/img2-lg.jpg" title="Image 2"><img src="https://es.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://es.js.cx/gallery/img3-lg.jpg" title="Image 3"><img src="https://es.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://es.js.cx/gallery/img4-lg.jpg" title="Image 4"><img src="https://es.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://es.js.cx/gallery/img5-lg.jpg" title="Image 5"><img src="https://es.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://es.js.cx/gallery/img6-lg.jpg" title="Image 6"><img src="https://es.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+
# Galería de imágenes
66

7-
Create an image gallery where the main image changes by the click on a thumbnail.
7+
Crea una galería de imágenes donde la imagen principal cambia al hacer clic en una miniatura.
88

9-
Like this:
9+
Así:
1010

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

13-
P.S. Use event delegation.
13+
P.D. Utiliza la delegación de eventos.

0 commit comments

Comments
 (0)