@@ -184,15 +182,15 @@ Any handler can listen for that event with `rabbit.addEventListener('hide',...)` =\_Y_/= {>o<}- + ``` -Please note: the event must have the flag `cancelable: true`, otherwise the call `event.preventDefault()` is ignored. +Nota bene: l'evento deve avere il flag `cancelable: true`, altrimenti la chiamata `event.preventDefault()` verrà ignorata. -## Events-in-events are synchronous +## Gli eventi annidati sono sincroni -Usually events are processed in a queue. That is: if the browser is processing `onclick` and a new event occurs, e.g. mouse moved, then it's handling is queued up, corresponding `mousemove` handlers will be called after `onclick` processing is finished. +Solitamente gli eventi vengono elaborati in una coda. Ossia: se il browser sta elaborando `onclick` e viene generato un nuovo evento, ad esempio il mouse viene mosso, il suo gestore verrà messo in coda, ed i corrispondenti gestori di `mousemove` verranno chiamati dopo che l'elaborazione di `onclick` sarà terminata. -The notable exception is when one event is initiated from within another one, e.g. using `dispatchEvent`. Such events are processed immediately: the new event handlers are called, and then the current event handling is resumed. +L'eccezione degna di nota è quando un evento viene inizializzato all'interno di un altro, ad esempio usando `dispatchEvent`. Questi eventi vengono elaborati immediatamente: i gestori del nuovo evento vengono chiamati, e successivamente viene ristabilita la gestione dell'evento corrente. -For instance, in the code below the `menu-open` event is triggered during the `onclick`. +Per esempio, nel codice seguente l'evento `menu-open` viene innescato durante `onclick`. -It's processed immediately, without waiting for `onclick` handler to end: +Viene processato immediatamente, senza attendere che il gestore di `onclick` abbia terminato: ```html run autorun - + ``` -The output order is: 1 -> nested -> 2. +L'ordine di output è: 1 -> annidato -> 2. -Please note that the nested event `menu-open` is caught on the `document`. The propagation and handling of the nested event is finished before the processing gets back to the outer code (`onclick`). +Nota bene che l'evento annidato `menu-open` viene catturato nel `document`. La propagazione e la gestione dell'evento annidato vengono eseguiti e completati prima che l'elaborazione torni al codice esterno (`onclick`). -That's not only about `dispatchEvent`, there are other cases. If an event handler calls methods that trigger other events -- they are processed synchronously too, in a nested fashion. +Questo non vale solo per `dispatchEvent`, ma esistono altri casi. Se un gestore di evento chiama metodi che innescano altri eventi -- anche questi vengono elaborati in maniera sincrona, in modo annidato. -Let's say we don't like it. We'd want `onclick` to be fully processed first, independently from `menu-open` or any other nested events. +Ora mettiamo il caso che questa cosa non ci stia bene, e che invece volessimo che `onclick` venisse elaborato per primo, indipendentemente da `menu-open` o prima di qualunque altro evento interno. -Then we can either put the `dispatchEvent` (or another event-triggering call) at the end of `onclick` or, maybe better, wrap it in the zero-delay `setTimeout`: +Allora potremmo sia inserire `dispatchEvent` (o un altra chiamata che generi un evento) alla fine di `onclick` oppure, forse anche meglio, incapsularlo in un `setTimeout` a ritardo zero: ```html run - + ``` -Now `dispatchEvent` runs asynchronously after the current code execution is finished, including `menu.onclick`, so event handlers are totally separate. +Adesso `dispatchEvent` viene eseguito in maniera asincrona dopo che l'esecuzione del codice corrente è terminata, incluso `menu.onclick`, ed in questo modo i gestori sono totalmente separati. -The output order becomes: 1 -> 2 -> nested. +L'ordine di output diventa: 1 -> 2 -> annidato. -## Summary +## Riepilogo -To generate an event from code, we first need to create an event object. +Per generare un evento dal codice, dobbiamo prima di tutto, creare un oggetto evento. -The generic `Event(name, options)` constructor accepts an arbitrary event name and the `options` object with two properties: -- `bubbles: true` if the event should bubble. -- `cancelable: true` if the `event.preventDefault()` should work. +Il costruttore generico `Event(name, options)` accetta un nome di evento arbitrario e un oggetto `options`, con due proprietà: +- `bubbles: true` se l'evento deve fare bubbling. +- `cancelable: true` se `event.preventDefault()` deve poter funzionare. -Other constructors of native events like `MouseEvent`, `KeyboardEvent` and so on accept properties specific to that event type. For instance, `clientX` for mouse events. +Altri costruttori di eventi nativi come `MouseEvent`, `KeyboardEvent` e così via, accettano proprietà specifiche per quel tipo di evento. Ad esempio, `clientX` per gli eventi del mouse. -For custom events we should use `CustomEvent` constructor. It has an additional option named `detail`, we should assign the event-specific data to it. Then all handlers can access it as `event.detail`. +Per eventi personalizzati dovremmo usare il costruttore `CustomEvent`, il quale ha una opzione aggiuntiva chiamata `detail`, per potervi assegnare i dati specifici del tipo di evento, ai quali i gestori potranno accedere tramite `event.detail`. -Despite the technical possibility of generating browser events like `click` or `keydown`, we should use them with great care. +Nonostante tecnicamente esista la possibilità di generare eventi del browser come `click` o `keydown`, dovremmo usarli con molta attenzione. -We shouldn't generate browser events as it's a hacky way to run handlers. That's bad architecture most of the time. +Non dovremmo generare eventi del browser perché è una pratica poco elegante e sporca nell'esecuzione dei gestori. La maggior parte delle volte, si tratta di cattiva architettura. -Native events might be generated: +Gli eventi nativi possono essere generati: -- As a dirty hack to make 3rd-party libraries work the needed way, if they don't provide other means of interaction. -- For automated testing, to "click the button" in the script and see if the interface reacts correctly. +- Come un modo poco pulito per far sì che delle librerie di terze parti lavorino nella maniera voluta, se queste non forniscono altri modi con cui poter interagire. +- Per test automatici, per "cliccare il pulsante" nello script e vedere se l'interfaccia risponde correttamente. -Custom events with our own names are often generated for architectural purposes, to signal what happens inside our menus, sliders, carousels etc. +Gli eventi personalizzati di nostra creazione, vengono spesso generati per scopi architetturali, per segnalare cosa succede dentro i nostri menù, sliders, caroselli, etc.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: