From 5e6f94b3eada886223353ff8ab9bf60b8c064d08 Mon Sep 17 00:00:00 2001 From: Marcello Date: Sun, 21 Mar 2021 11:56:12 +0100 Subject: [PATCH 1/9] Update 2-ui/1-document/08-styles-and-classes/article.md --- .../08-styles-and-classes/article.md | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/2-ui/1-document/08-styles-and-classes/article.md b/2-ui/1-document/08-styles-and-classes/article.md index 9154d43d6..b9163f8d4 100644 --- a/2-ui/1-document/08-styles-and-classes/article.md +++ b/2-ui/1-document/08-styles-and-classes/article.md @@ -1,29 +1,29 @@ -# Styles and classes +# Stili e classi -Before we get into JavaScript's ways of dealing with styles and classes -- here's an important rule. Hopefully it's obvious enough, but we still have to mention it. +Prima di cominciare a trattare i modi in cui JavaScript interagisce con gli stili e le classi -- ecco una regola importante. Si spera che sia abbastanza scontata, ma non guasta menzionarla ancora. -There are generally two ways to style an element: +Ci sono in genere due modi di applicare uno stile ad un elemento: -1. Create a class in CSS and add it: `
` -2. Write properties directly into `style`: `
`. +1. Creare una classe CSS ed aggiungerla: `
` +2. Scrivere direttamente proprietà dentro `style`: `
`. -JavaScript can modify both classes and `style` properties. +JavaScript può modificare sia le classi sia le proprietà all'interno di `style`. -We should always prefer CSS classes to `style`. The latter should only be used if classes "can't handle it". +Dovremmo sempre preferire le classi CSS a `style`. Quest'ultimo dovrebbe essere usato solo se le classi non sono sufficienti. -For example, `style` is acceptable if we calculate coordinates of an element dynamically and want to set them from JavaScript, like this: +Per esempio, è ragionevole l'uso di `style` se calcoliamo dinamicamente le coordinate di un elemento e vogliamo impostarle con JavaScript, come in casi analoghi: ```js -let top = /* complex calculations */; -let left = /* complex calculations */; +let top = /* calcoli complessi */; +let left = /* calcoli complessi */; -elem.style.left = left; // e.g '123px', calculated at run-time -elem.style.top = top; // e.g '456px' +elem.style.left = left; // es '123px', calcolato al momento dell'esecuzione +elem.style.top = top; // es '456px' ``` -For other cases, like making the text red, adding a background icon -- describe that in CSS and then add the class (JavaScript can do that). That's more flexible and easier to support. +Per gli altri casi, come rendere rosso un testo, aggiungere un'icona di sfondo -- definiamo degli stili CSS e poi applichiamo la classe con JavaScript. È più flessibile e più facile da supportare. -## className and classList +## className e classList Changing a class is one of the most often used actions in scripts. From adaf44ec237266c39cbca2fc19e5582b26b502a5 Mon Sep 17 00:00:00 2001 From: Marcello Date: Sun, 21 Mar 2021 19:48:19 +0100 Subject: [PATCH 2/9] Update 2-ui\1-document\08-styles-and-classes\article.md --- .../08-styles-and-classes/article.md | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/2-ui/1-document/08-styles-and-classes/article.md b/2-ui/1-document/08-styles-and-classes/article.md index b9163f8d4..7f1eb96f4 100644 --- a/2-ui/1-document/08-styles-and-classes/article.md +++ b/2-ui/1-document/08-styles-and-classes/article.md @@ -25,13 +25,13 @@ Per gli altri casi, come rendere rosso un testo, aggiungere un'icona di sfondo - ## className e classList -Changing a class is one of the most often used actions in scripts. +Modificare una classe è una delle operazioni più comuni negli script. -In the ancient time, there was a limitation in JavaScript: a reserved word like `"class"` could not be an object property. That limitation does not exist now, but at that time it was impossible to have a `"class"` property, like `elem.class`. +Anticamente c'era una limitazione in JavaScript: una parola riservata come `"class"` non poteva essere una proprietà di un oggetto. Tale limitazione non c'è più, ma a quel tempo era impossibile avere una proprietà `"class"` come `elem.class`. -So for classes the similar-looking property `"className"` was introduced: the `elem.className` corresponds to the `"class"` attribute. +Quindi per le classi fu introdotta la proprietà `"className"` che è simile: l'attributo `"class"` ha il suo corrispettivo DOM in `elem.className`. -For instance: +Per esempio: ```html run @@ -41,19 +41,19 @@ For instance: ``` -If we assign something to `elem.className`, it replaces the whole string of classes. Sometimes that's what we need, but often we want to add/remove a single class. +Se assegniamo un valore a `elem.className` rimpiazziamo l'intero contenuto dell'attributo `"class"`. Talvolta è il risultato che vogliamo ottenere, spesso invece vogliamo aggiungere/rimuovere una singola classe. -There's another property for that: `elem.classList`. +Esiste un'altra proprietà per quello: `elem.classList`. -The `elem.classList` is a special object with methods to `add/remove/toggle` a single class. +La proprietà `elem.classList` è uno speciale oggetto con i metodi `add/remove/toggle` per aggiungere/rimuovere/alternare una singola classe. -For instance: +Per esempio: ```html run ``` -## Element style +## La proprietà style di un elemento -The property `elem.style` is an object that corresponds to what's written in the `"style"` attribute. Setting `elem.style.width="100px"` works the same as if we had in the attribute `style` a string `width:100px`. +La proprietà `elem.style` è un oggetto corrispondente a ciò che è scritto dentro l'attributo `"style"`. Impostando `elem.style.width="100px"` otteniamo lo stesso effetto che otterremmo scrivendo `width:100px` dentro l'attributo `style`. -For multi-word property the camelCase is used: +Per le proprietà composte da più di una parola, si usa l'iniziale maiuscola dalla seconda parola in poi (camel case): ```js no-beautify background-color => elem.style.backgroundColor @@ -94,16 +94,16 @@ z-index => elem.style.zIndex border-left-width => elem.style.borderLeftWidth ``` -For instance: +Per esempio: ```js run document.body.style.backgroundColor = prompt('background color?', 'green'); ``` -````smart header="Prefixed properties" -Browser-prefixed properties like `-moz-border-radius`, `-webkit-border-radius` also follow the same rule: a dash means upper case. +````smart header="Proprietà con prefisso" +Le proprietà con il prefisso del browser come `-moz-border-radius`, `-webkit-border-radius` seguono anch'esse la stessa regola: un trattino comporta l'uso del maiuscolo. -For instance: +Per esempio: ```js button.style.MozBorderRadius = '5px'; @@ -111,7 +111,7 @@ button.style.WebkitBorderRadius = '5px'; ``` ```` -## Resetting the style property +## Resettare la proprietà style Sometimes we want to assign a style property, and later remove it. From ae39ebfee84698207651da1c360b1d33bf512477 Mon Sep 17 00:00:00 2001 From: idrusma Date: Mon, 22 Mar 2021 10:05:18 +0100 Subject: [PATCH 3/9] Update 2-ui\1-document\08-styles-and-classes\article.md --- .../08-styles-and-classes/article.md | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/2-ui/1-document/08-styles-and-classes/article.md b/2-ui/1-document/08-styles-and-classes/article.md index 7f1eb96f4..b6dcc2d3d 100644 --- a/2-ui/1-document/08-styles-and-classes/article.md +++ b/2-ui/1-document/08-styles-and-classes/article.md @@ -113,31 +113,32 @@ button.style.WebkitBorderRadius = '5px'; ## Resettare la proprietà style -Sometimes we want to assign a style property, and later remove it. +Talvolta vogliamo assegnare uno stile e successivamente rimuoverlo. -For instance, to hide an element, we can set `elem.style.display = "none"`. +Per esempio, per nascondere un elemento, possiamo impostare `elem.style.display = "none"`. + +Successivamente potremmo voler rimuovere `style.display` come se non fosse impostato. Invece di `delete elem.style.display` dovremmo assegnargli una stringa vuota: `elem.style.display = ""`. -Then later we may want to remove the `style.display` as if it were not set. Instead of `delete elem.style.display` we should assign an empty string to it: `elem.style.display = ""`. ```js run -// if we run this code, the will blink +// se eseguiamo questo codice, il lampeggerà document.body.style.display = "none"; // hide -setTimeout(() => document.body.style.display = "", 1000); // back to normal +setTimeout(() => document.body.style.display = "", 1000); // ritorna alla normalità ``` -If we set `style.display` to an empty string, then the browser applies CSS classes and its built-in styles normally, as if there were no such `style.display` property at all. +Se assegniamo una stringa vuota a `style.display`, il browser applica come di consueto le classi CSS ed i suoi stili predefiniti, come se non ci fosse alcuna proprietà `style.display`. -````smart header="Full rewrite with `style.cssText`" -Normally, we use `style.*` to assign individual style properties. We can't set the full style like `div.style="color: red; width: 100px"`, because `div.style` is an object, and it's read-only. +````smart header="Riscrittura completa con `style.cssText`" +Di solito usiamo `style.*` per assegnare le proprietà di stile individualmente. Non possiamo impostare tutti gli stili in questo modo `div.style="color: red; width: 100px"`, perché `div.style` è un oggetto ed è in sola lettura. -To set the full style as a string, there's a special property `style.cssText`: +Per impostare tutti gli stili come stringa c'è una speciale proprietà `style.cssText`: ```html run
Button
``` -This property is rarely used, because such assignment removes all existing styles: it does not add, but replaces them. May occasionally delete something needed. But we can safely use it for new elements, when we know we won't delete an existing style. +Questa proprietà è usata di rado, poiché un tale assegnamento rimuove tutti gli stili esistenti: non li aggiunge, piuttosto li sostituisce. Potrebbe eliminare in modo fortuito qualcosa di necessario. Possiamo tuttavia usarla in sicurezza per i nuovi elementi, quando siamo certi che non cancelleremo uno stile preesistente. -The same can be accomplished by setting an attribute: `div.setAttribute('style', 'color: red...')`. +Lo stesso risultato può essere ottenuto impostando un attributo: `div.setAttribute('style', 'color: red...')`. ```` -## Mind the units +## Presta attenzione alle unità Don't forget to add CSS units to values. From 338fbcbbc6bfa3a8b8f46e05d8ae2be2961a64e2 Mon Sep 17 00:00:00 2001 From: idrusma Date: Tue, 23 Mar 2021 09:34:35 +0100 Subject: [PATCH 4/9] Update 2-ui\1-document\08-styles-and-classes\article.md --- .../08-styles-and-classes/article.md | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/2-ui/1-document/08-styles-and-classes/article.md b/2-ui/1-document/08-styles-and-classes/article.md index b6dcc2d3d..b03be862c 100644 --- a/2-ui/1-document/08-styles-and-classes/article.md +++ b/2-ui/1-document/08-styles-and-classes/article.md @@ -154,22 +154,22 @@ Questa proprietà è usata di rado, poiché un tale assegnamento rimuove tutti g Lo stesso risultato può essere ottenuto impostando un attributo: `div.setAttribute('style', 'color: red...')`. ```` -## Presta attenzione alle unità +## Presta attenzione alle unità di misura -Don't forget to add CSS units to values. +Non dimenticare di aggiungere le unità di misura CSS ai valori. -For instance, we should not set `elem.style.top` to `10`, but rather to `10px`. Otherwise it wouldn't work: +Ad esempio, non dovremmo impostare `elem.style.top` a `10`, piuttosto a `10px`. Altrimenti non funzionerebbe: ```html run height=100 ``` -...But what if we need, say, to increase the margin by `20px`? We would want the current value of it. +...ma cosa dovremmo fare se avessimo bisogno, per dire, di incrementare il margine di `20px`? Dovremmo prima conoscerne il valore corrente. -There's another method for that: `getComputedStyle`. +C'è un altro metodo per quello: `getComputedStyle`. -The syntax is: +La sintassi è: ```js getComputedStyle(element, [pseudo]) ``` element -: Element to read the value for. +: L'elemento di cui leggere il valore. pseudo -: A pseudo-element if required, for instance `::before`. An empty string or no argument means the element itself. +: Uno pseudo-elemento se richiesto, per esempio `::before`. Una stringa vuota o nessun argomento significa l'elemento stesso. -The result is an object with styles, like `elem.style`, but now with respect to all CSS classes. +Il risultato è un oggetto con gli stili, come `elem.style`, ma, a differenza di quello, tiene conto di tutte le classi CSS. -For instance: +Per esempio: ```html run height=100 @@ -238,7 +238,7 @@ For instance: ``` ```` -```smart header="Styles applied to `:visited` links are hidden!" -Visited links may be colored using `:visited` CSS pseudoclass. +```smart header="Gli stili applicati ai link `:visited` sono nascosti!" +I link visitati possono ricevere un colore tramite la pseudoclasse CSS `:visited`. -But `getComputedStyle` does not give access to that color, because otherwise an arbitrary page could find out whether the user visited a link by creating it on the page and checking the styles. +Tuttavia `getComputedStyle non dà accesso a quel colore, poiché diversamente una pagina arbitraria potrebbe scoprire se l'utente ha visitato un link creandolo sulla pagina e verificandone gli stili. JavaScript may not see the styles applied by `:visited`. And also, there's a limitation in CSS that forbids applying geometry-changing styles in `:visited`. That's to guarantee that there's no side way for an evil page to test if a link was visited and hence to break the privacy. ``` From ba5acd95dbdc1490689617fba54d82429b180c73 Mon Sep 17 00:00:00 2001 From: idrusma Date: Tue, 23 Mar 2021 12:24:41 +0100 Subject: [PATCH 7/9] Update 2-ui\1-document\08-styles-and-classes\article.md --- .../08-styles-and-classes/article.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/2-ui/1-document/08-styles-and-classes/article.md b/2-ui/1-document/08-styles-and-classes/article.md index 2516aae1c..3b3c0ea5a 100644 --- a/2-ui/1-document/08-styles-and-classes/article.md +++ b/2-ui/1-document/08-styles-and-classes/article.md @@ -283,22 +283,22 @@ I link visitati possono ricevere un colore tramite la pseudoclasse CSS `:visited Tuttavia `getComputedStyle non dà accesso a quel colore, poiché diversamente una pagina arbitraria potrebbe scoprire se l'utente ha visitato un link creandolo sulla pagina e verificandone gli stili. -JavaScript may not see the styles applied by `:visited`. And also, there's a limitation in CSS that forbids applying geometry-changing styles in `:visited`. That's to guarantee that there's no side way for an evil page to test if a link was visited and hence to break the privacy. +JavaScript potrebbe non rilevare gli stili applicati da `:visited`. C'è una limitazione nei CSS, inoltre, che vieta su `:visited` l'applicazione di stili che modifichino le proprietà geometriche. Questo per garantire che non ci sia, per una pagina malevola, una via traversa di testare se un link è stato visitato e quindi di violare la privacy. ``` ## Riepilogo -To manage classes, there are two DOM properties: +Per gestire le classi ci sono due proprietà DOM: -- `className` -- the string value, good to manage the whole set of classes. -- `classList` -- the object with methods `add/remove/toggle/contains`, good for individual classes. +- `className` -- il valore stringa, ottimo per gestire l'intero insieme delle classi. +- `classList` -- il valore oggetto con i metodi `add/remove/toggle/contains`, ottimo per gestire le classi individualmente. -To change the styles: +Per modificare gli stili: -- The `style` property is an object with camelCased styles. Reading and writing to it has the same meaning as modifying individual properties in the `"style"` attribute. To see how to apply `important` and other rare stuff -- there's a list of methods at [MDN](mdn:api/CSSStyleDeclaration). +- La proprietà `style` è un oggetto contenente gli stili CSS, le proprietà composte da più di una parola sono trascritte in camel case. Leggere e scrivere con questa proprietà equivale a modificare individualmente gli stili con l'attributo `"style"`. Per vedere come applicare `important` e per altre esigenze poco comuni -- c'è una lista di metodi su [MDN](mdn:api/CSSStyleDeclaration). -- The `style.cssText` property corresponds to the whole `"style"` attribute, the full string of styles. +- La proprietà `style.cssText` corrisponde al contenuto completo dell'attributo `"style"`, l'intera stringa degli stili. -To read the resolved styles (with respect to all classes, after all CSS is applied and final values are calculated): +Per leggere gli stili determinati (che tengono conto di tutte le classi, dopo che tutti i CSS sono stati applicati e sono stati calcolati i valori risultanti): -- The `getComputedStyle(elem, [pseudo])` returns the style-like object with them. Read-only. +- Il metodo `getComputedStyle(elem, [pseudo])` restituisce un oggetto simile a `style` con tali valori. Questi sono in sola lettura. From 4cd4925d2e317f0b89c8948a93b8bc34c051ce3e Mon Sep 17 00:00:00 2001 From: idrusma Date: Tue, 23 Mar 2021 12:52:02 +0100 Subject: [PATCH 8/9] Update 2-ui\1-document\08-styles-and-classes --- .../solution.view/index.html | 2 +- .../source.view/index.html | 4 ++-- .../2-create-notification/task.md | 20 +++++++++---------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/2-ui/1-document/08-styles-and-classes/2-create-notification/solution.view/index.html b/2-ui/1-document/08-styles-and-classes/2-create-notification/solution.view/index.html index dc4eeec9f..8ef5d48f5 100755 --- a/2-ui/1-document/08-styles-and-classes/2-create-notification/solution.view/index.html +++ b/2-ui/1-document/08-styles-and-classes/2-create-notification/solution.view/index.html @@ -32,7 +32,7 @@

Notification is on the right

setTimeout(() => notification.remove(), 1500); } - // test it + // prova let i = 1; setInterval(() => { showNotification({ diff --git a/2-ui/1-document/08-styles-and-classes/2-create-notification/source.view/index.html b/2-ui/1-document/08-styles-and-classes/2-create-notification/source.view/index.html index b5e2f83f7..c92597797 100755 --- a/2-ui/1-document/08-styles-and-classes/2-create-notification/source.view/index.html +++ b/2-ui/1-document/08-styles-and-classes/2-create-notification/source.view/index.html @@ -16,10 +16,10 @@

Notification is on the right