Skip to content

Commit 69c3829

Browse files
authored
Merge pull request #212 from pierangelomiceli/browser_default_actions
Browser default actions
2 parents 959a107 + 11e75e6 commit 69c3829

File tree

7 files changed

+121
-121
lines changed

7 files changed

+121
-121
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+
Quando il browser legge un attributo `on*` come `onclick`, crea il gestore dal suo contenuto.
22

3-
For `onclick="handler()"` the function will be:
3+
Nel caso di `onclick="handler()"` la funzione sarà:
44

55
```js
66
function(event) {
7-
handler() // the content of onclick
7+
handler() // il contenuto del click
88
}
99
```
1010

11-
Now we can see that the value returned by `handler()` is not used and does not affect the result.
11+
Possiamo osservare che il valore restituito da `handler()` non viene usato e non influenza il risultato.
1212

13-
The fix is simple:
13+
Il fix è semplice:
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+
Possiamo anche usare `event.preventDefault()`, come in questo esempio:
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+
# Perché "return false" non funziona?
66

7-
Why in the code below `return false` doesn't work at all?
7+
Perché nel seguente codice `return false` non funziona per niente?
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()">il browser andrà su w3.org</a>
1818
```
1919

20-
The browser follows the URL on click, but we don't want it.
20+
Il browser andrà all'URL al click, ma non è ciò che vogliamo.
2121

22-
How to fix?
22+
Come si può sistemare?
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+
Questo è un ottimo uso del pattern event delegation.
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+
In applicazioni concrete, invece di chiedere, potremmo inviare una richiesta di "logging" al server, che salvi l'informazione relativa al momento in cui l'utente ha deciso di abbandonare la pagina. Oppure potremmo caricare il contenuto e mostrarlo direttamente in pagina (se permesso).
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+
Tutto ciò di cui abbiamo bisogno è di catturare i `contents.onclick` ed usare `confirm` per chiedere all'utente. Una buona idea potrebbe essere quella di usare `link.getAttribute('href')` invece di `link.href` per l'URL. Guarda la soluzione per i dettagli.

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+
# Catturare i links nell'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+
Fare in modo che tutti i links dentro l'elemento con `id="contents"` chiedano all'utente se vuole davvero abbandonare la pagina al click. Se risponde no, allora non deve seguire il link.
88

9-
Like this:
9+
Come nell'esempio seguente:
1010

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

13-
Details:
13+
Dettagli:
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+
- L'HTML dentro l'elemento potrebbe essere caricato o rigenerato in qualunque istante, quindi non possiamo trovare tutti i links ed inserirvi dei gestori all'interno. Utilizzare invece la event delegation.
16+
- Il contenuto può contenere tags annidati. Anche dentro i links, per esempio potremmo avere `<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 soluzione è quella di assegnare il gestore al contenitore e tenere traccia dei click. Se un click è sul link `<a>`, allora modificare il `src` di `#largeImg` con l'`href` della thumbnail.

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+
# Galleria di immagini
66

7-
Create an image gallery where the main image changes by the click on a thumbnail.
7+
Creare una galleria di immagini dove l'immagine principale cambi al click su una thumbnail.
88

9-
Like this:
9+
Come in questo esempio:
1010

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

13-
P.S. Use event delegation.
13+
P.S.: Utilizzate event delegation.

0 commit comments

Comments
 (0)