Skip to content

Commit b1089eb

Browse files
committed
WIP
1 parent 0b207b5 commit b1089eb

File tree

7 files changed

+60
-61
lines changed

7 files changed

+60
-61
lines changed

2-ui/1-document/06-dom-attributes-and-properties/1-get-user-attribute/solution.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
<html>
55
<body>
66

7-
<div data-widget-name="menu">Choose the genre</div>
7+
<div data-widget-name="menu">Escolha o gênero</div>
88

99
<script>
10-
// getting it
10+
// Obtendo o elemento
1111
let elem = document.querySelector('[data-widget-name]');
1212
13-
// reading the value
13+
// lendo o valor
1414
alert(elem.dataset.widgetName);
15-
// or
15+
// ou
1616
alert(elem.getAttribute('data-widget-name'));
1717
</script>
1818
</body>

2-ui/1-document/06-dom-attributes-and-properties/1-get-user-attribute/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 5
22

33
---
44

5-
# Get the attribute
5+
# Obtendo o atributo
66

7-
Write the code to select the element with `data-widget-name` attribute from the document and to read its value.
7+
Escreva o código para obter do documento o elemento com o atributo `data-widget-name` e leia seu valor.
88

99
```html run
1010
<!DOCTYPE html>
@@ -14,7 +14,7 @@ Write the code to select the element with `data-widget-name` attribute from the
1414
<div data-widget-name="menu">Choose the genre</div>
1515

1616
<script>
17-
/* your code */
17+
/* seu código */
1818
</script>
1919
</body>
2020
</html>

2-ui/1-document/06-dom-attributes-and-properties/2-yellow-links/solution.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
Primeiro, precisamos encontrar todas referências externas.
12

2-
First, we need to find all external references.
3+
Há duas formas.
34

4-
There are two ways.
5-
6-
The first is to find all links using `document.querySelectorAll('a')` and then filter out what we need:
5+
A primeira é encontrar todos os links usando `document.querySelectorAll('a')` e então filtrar o que precisamos:
76

87
```js
98
let links = document.querySelectorAll('a');
@@ -12,23 +11,23 @@ for (let link of links) {
1211
*!*
1312
let href = link.getAttribute('href');
1413
*/!*
15-
if (!href) continue; // no attribute
14+
if (!href) continue; // sem atributo
1615

17-
if (!href.includes('://')) continue; // no protocol
16+
if (!href.includes('://')) continue; // sem protocolo
1817

1918
if (href.startsWith('http://internal.com')) continue; // internal
2019

2120
link.style.color = 'orange';
2221
}
2322
```
2423

25-
Please note: we use `link.getAttribute('href')`. Not `link.href`, because we need the value from HTML.
24+
Por favor observe: usamos `link.getAttribute('href')`. Não `link.href`, porque precisamos do valor do HTML.
2625

27-
...Another, simpler way would be to add the checks to CSS selector:
26+
...Outra forma mais simples seria apenas adicionar os checks ao seletor CSS
2827

2928
```js
30-
// look for all links that have :// in href
31-
// but href doesn't start with http://internal.com
29+
// procura todos os links que tem :// em href
30+
// mas href não começa com http://internal.com
3231
let selector = 'a[href*="://"]:not([href^="http://internal.com"])';
3332
let links = document.querySelectorAll(selector);
3433

2-ui/1-document/06-dom-attributes-and-properties/2-yellow-links/solution.view/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<body>
44

5-
<a name="list">The list:</a>
5+
<a name="list">A lista:</a>
66
<ul>
77
<li><a href="http://google.com">http://google.com</a></li>
88
<li><a href="/tutorial">/tutorial.html</a></li>

2-ui/1-document/06-dom-attributes-and-properties/2-yellow-links/source.view/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<body>
44

5-
<a name="list">The list:</a>
5+
<a name="list">A lista:</a>
66
<ul>
77
<li><a href="http://google.com">http://google.com</a></li>
88
<li><a href="/tutorial">/tutorial.html</a></li>
@@ -13,7 +13,7 @@
1313
</ul>
1414

1515
<script>
16-
// ...your code...
16+
// ...seu código...
1717
</script>
1818

1919
</body>

2-ui/1-document/06-dom-attributes-and-properties/2-yellow-links/task.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ importance: 3
22

33
---
44

5-
# Make external links orange
5+
# Faça com que links externos fiquem laranja
66

7-
Make all external links orange by altering their `style` property.
7+
Faça com que todos links externos fiquem laranja alterando a propriedade `style`.
88

9-
A link is external if:
10-
- Its `href` has `://` in it
11-
- But doesn't start with `http://internal.com`.
9+
Um link é externo se:
10+
- O `href` tem `://`.
11+
- Mas não começa com `http://internal.com`.
1212

13-
Example:
13+
Por exemplo:
1414

1515
```html run
16-
<a name="list">the list</a>
16+
<a name="list">a lista</a>
1717
<ul>
1818
<li><a href="http://google.com">http://google.com</a></li>
1919
<li><a href="/tutorial">/tutorial.html</a></li>
@@ -24,12 +24,12 @@ Example:
2424
</ul>
2525

2626
<script>
27-
// setting style for a single link
27+
// Definindo o estilo para um único link
2828
let link = document.querySelector('a');
2929
link.style.color = 'orange';
3030
</script>
3131
```
3232

33-
The result should be:
33+
O resultado deverá ser:
3434

3535
[iframe border=1 height=180 src="solution"]

2-ui/1-document/06-dom-attributes-and-properties/article.md

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,76 @@
1-
# Attributes and properties
1+
# Atributos e propriedades
22

3-
When the browser loads the page, it "reads" (another word: "parses") the HTML and generates DOM objects from it. For element nodes, most standard HTML attributes automatically become properties of DOM objects.
3+
Quando navegador carrega a página, ele "lê" (outra palavra: "analisa") o HTML e gera objetos DOM a partir dela. Para nós de elementos, a maior parte dos atributos HTML padrão automaticamente se tornam propriedades de objetos DOM.
44

5-
For instance, if the tag is `<body id="page">`, then the DOM object has `body.id="page"`.
5+
Por exemplo, se a tag é `<body id="page">`, então o objeto DOM tem `body.id="page"`.
66

7-
But the attribute-property mapping is not one-to-one! In this chapter we'll pay attention to separate these two notions, to see how to work with them, when they are the same, and when they are different.
7+
Mas o mapeamento atributo-propriedade não é de um para um! Nesse capítulo vamos prestar atenção em separar essas duas noções, entender como trabalhar com eles, quando eles são os mesmos e quando eles são diferentes.
88

9-
## DOM properties
9+
## Propriedades DOM
1010

11-
We've already seen built-in DOM properties. There are a lot. But technically no one limits us, and if there aren't enough, we can add our own.
11+
Nós já vimos propriedades DOM incorporadas. Há várias. Mas tecnicamente ninguém nos limita, e se não há propriedades suficientes, nós podemos adicionar nossas próprias.
1212

13-
DOM nodes are regular JavaScript objects. We can alter them.
13+
Nós DOM são objetos JavaScript. Nós podemos alterar eles.
1414

15-
For instance, let's create a new property in `document.body`:
15+
Por exemplo, vamos criar uma propriedade nova em `document.body`:
1616

1717
```js run
1818
document.body.myData = {
1919
name: 'Caesar',
20-
title: 'Imperator'
20+
title: 'Imperador'
2121
};
2222

23-
alert(document.body.myData.title); // Imperator
23+
alert(document.body.myData.title); // Imperador
2424
```
2525

26-
We can add a method as well:
26+
Nós podemos adicionar um método também:
2727

2828
```js run
2929
document.body.sayTagName = function() {
3030
alert(this.tagName);
3131
};
3232

33-
document.body.sayTagName(); // BODY (the value of "this" in the method is document.body)
33+
document.body.sayTagName(); // BODY (o valor de "this" no método é document.body)
3434
```
3535

36-
We can also modify built-in prototypes like `Element.prototype` and add new methods to all elements:
36+
Nós também podemos modificar prototypes incorporados como `Element.prototype` e adicionar novos métodos para todos elements:
3737

3838
```js run
3939
Element.prototype.sayHi = function() {
40-
alert(`Hello, I'm ${this.tagName}`);
40+
alert(`Olá, eu sou um ${this.tagName}`);
4141
};
4242

43-
document.documentElement.sayHi(); // Hello, I'm HTML
44-
document.body.sayHi(); // Hello, I'm BODY
43+
document.documentElement.sayHi(); // Olá, eu sou um HTML
44+
document.body.sayHi(); // Olá, eu sou um BODY
4545
```
4646

47-
So, DOM properties and methods behave just like those of regular JavaScript objects:
47+
Então, propriedades e métodos do DOM se comportam como qualquer objeto JavaScript:
4848

49-
- They can have any value.
50-
- They are case-sensitive (write `elem.nodeType`, not `elem.NoDeTyPe`).
49+
- Podem ter qualquer valor.
50+
- São sensíveis a letras maiúsculas e minúsculas (escreva `elem.nodeType`, não `elem.NoDeTyPe`).
5151

52-
## HTML attributes
52+
## Atributos HTML
5353

54-
In HTML, tags may have attributes. When the browser parses the HTML to create DOM objects for tags, it recognizes *standard* attributes and creates DOM properties from them.
54+
Em HTML, tags podem ter atributos. Quando o navegador analisa o HTML para criar objetos DOM para tags, ele reconhece atributos *padrões* e cria propriedades DOM para eles.
5555

56-
So when an element has `id` or another *standard* attribute, the corresponding property gets created. But that doesn't happen if the attribute is non-standard.
56+
Então quando um elemento tem `id` ou outro atributo *padrão*, a propriedade correspontente é criada. Mas isso não acontece se o atributo não for padrão.
5757

58-
For instance:
58+
Por exemplo:
5959
```html run
6060
<body id="test" something="non-standard">
6161
<script>
6262
alert(document.body.id); // test
6363
*!*
64-
// non-standard attribute does not yield a property
64+
// Atributo não padrão não resulta em uma propriedade
6565
alert(document.body.something); // undefined
6666
*/!*
6767
</script>
6868
</body>
6969
```
7070

71-
Please note that a standard attribute for one element can be unknown for another one. For instance, `"type"` is standard for `<input>` ([HTMLInputElement](https://html.spec.whatwg.org/#htmlinputelement)), but not for `<body>` ([HTMLBodyElement](https://html.spec.whatwg.org/#htmlbodyelement)). Standard attributes are described in the specification for the corresponding element class.
71+
Observe que um atributo padrão para um elemento pode ser desconhecido para outro elemento. Por exemplo, `"type"` é padrão para `<input>`([HTMLInputElement](https://html.spec.whatwg.org/#htmlinputelement)), mas não para `<body>` ([HTMLBodyElement](https://html.spec.whatwg.org/#htmlbodyelement)). Atributos padrão são descritos na especificação da classe correspondente ao elemento.
7272

73-
Here we can see it:
73+
Aqui nós podemos ver:
7474
```html run
7575
<body id="body" type="...">
7676
<input id="input" type="text">
@@ -83,14 +83,14 @@ Here we can see it:
8383
</body>
8484
```
8585

86-
So, if an attribute is non-standard, there won't be a DOM-property for it. Is there a way to access such attributes?
86+
Então, se um atributo não é padrão, não há uma propriedade DOM para ele. Há alguma forma de acessar esses atributos?
8787

88-
Sure. All attributes are accessible by using the following methods:
88+
Claro. Todos atributos são acessíveis usando os seguintes métodos:
8989

90-
- `elem.hasAttribute(name)` -- checks for existence.
91-
- `elem.getAttribute(name)` -- gets the value.
92-
- `elem.setAttribute(name, value)` -- sets the value.
93-
- `elem.removeAttribute(name)` -- removes the attribute.
90+
- `elem.hasAttribute(name)` -- checa a existencia.
91+
- `elem.getAttribute(name)` -- obtém o valor.
92+
- `elem.setAttribute(name, value)` -- defined um valor.
93+
- `elem.removeAttribute(name)` -- remove o atributo.
9494

9595
These methods operate exactly with what's written in HTML.
9696

0 commit comments

Comments
 (0)