Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@

<div id="container">
<div class="pane">
<h3>Horse</h3>
<p>The horse is one of two extant subspecies of Equus ferus. It is an odd-toed ungulate mammal belonging to the taxonomic family Equidae. The horse has evolved over the past 45 to 55 million years from a small multi-toed creature, Eohippus, into the large, single-toed animal of today.</p>
<h3>Cavalo</h3>
<p>O cavalo é uma das duas subespécies existentes de Equus ferus. É um mamífero ungulado de dedo ímpar pertencente à família taxonômica Equidae. O cavalo evoluiu nos últimos 45 a 55 milhões de anos, de uma pequena criatura de vários dedos, o Eohippus, até o grande animal de dedo único de hoje.</p>
<button class="remove-button">[x]</button>
</div>
<div class="pane">
<h3>Donkey</h3>
<p>The donkey or ass (Equus africanus asinus) is a domesticated member of the horse family, Equidae. The wild ancestor of the donkey is the African wild ass, E. africanus. The donkey has been used as a working animal for at least 5000 years.</p>
<h3>Burro</h3>
<p>O burro ou jumento (Equus africanus asinus) é um membro domesticado da família dos cavalos, Equidae. O ancestral selvagem do burro é o jumento-selvagem-africano, E. africanus. O burro é usado como animal de trabalho há pelo menos 5000 anos.</p>
<button class="remove-button">[x]</button>
</div>
<div class="pane">
<h3>Cat</h3>
<p>The domestic cat (Latin: Felis catus) is a small, typically furry, carnivorous mammal. They are often called house cats when kept as indoor pets or simply cats when there is no need to distinguish them from other felids and felines. Cats are often valued by humans for companionship and for their ability to hunt vermin.
<h3>Gato</h3>
<p>O gato doméstico (em latim: Felis catus) é um mamífero carnívoro pequeno, geralmente peludo. Eles são frequentemente chamados de gatos caseiros quando mantidos como animais de estimação dentro de casa, ou simplesmente gatos quando não há necessidade de distingui-los de outros felídeos e felinos. Os gatos são frequentemente valorizados pelos humanos por companhia e por sua habilidade de caçar pragas.
</p>
<button class="remove-button">[x]</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@

<div id="container">
<div class="pane">
<h3>Horse</h3>
<p>The horse is one of two extant subspecies of Equus ferus. It is an odd-toed ungulate mammal belonging to the taxonomic family Equidae. The horse has evolved over the past 45 to 55 million years from a small multi-toed creature, Eohippus, into the large, single-toed animal of today.</p>
<h3>Cavalo</h3>
<p>O cavalo é uma das duas subespécies existentes de Equus ferus. É um mamífero ungulado de dedo ímpar pertencente à família taxonômica Equidae. O cavalo evoluiu nos últimos 45 a 55 milhões de anos, de uma pequena criatura de vários dedos, o Eohippus, até o grande animal de dedo único de hoje.</p>
<button class="remove-button">[x]</button>
</div>
<div class="pane">
<h3>Donkey</h3>
<p>The donkey or ass (Equus africanus asinus) is a domesticated member of the horse family, Equidae. The wild ancestor of the donkey is the African wild ass, E. africanus. The donkey has been used as a working animal for at least 5000 years.</p>
<h3>Burro</h3>
<p>O burro ou jumento (Equus africanus asinus) é um membro domesticado da família dos cavalos, Equidae. O ancestral selvagem do burro é o jumento-selvagem-africano, E. africanus. O burro é usado como animal de trabalho há pelo menos 5000 anos.</p>
<button class="remove-button">[x]</button>
</div>
<div class="pane">
<h3>Cat</h3>
<p>The domestic cat (Latin: Felis catus) is a small, typically furry, carnivorous mammal. They are often called house cats when kept as indoor pets or simply cats when there is no need to distinguish them from other felids and felines. Cats are often valued by humans for companionship and for their ability to hunt vermin.
<h3>Gato</h3>
<p>O gato doméstico (em latim: Felis catus) é um mamífero carnívoro pequeno, geralmente peludo. Eles são frequentemente chamados de gatos caseiros quando mantidos como animais de estimação dentro de casa, ou simplesmente gatos quando não há necessidade de distingui-los de outros felídeos e felinos. Os gatos são frequentemente valorizados pelos humanos por companhia e por sua habilidade de caçar pragas.
</p>
<button class="remove-button">[x]</button>
</div>
</div>

<script>
// ...your code...
// ...seu código...
</script>

</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ importance: 5

---

# Hide messages with delegation
# Oculte mensagens com delegação

There's a list of messages with removal buttons `[x]`. Make the buttons work.
Há uma lista de mensagens com botões de remoção `[x]`. Faça os botões funcionarem.

Like this:
Assim:

[iframe src="solution" height=420]

P.S. Should be only one event listener on the container, use event delegation.
P.S. Deve haver apenas um manipulador de evento no container, use delegação de eventos.
6 changes: 3 additions & 3 deletions 2-ui/2-events/03-event-delegation/2-sliding-tree/solution.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The solution has two parts.
A solução tem duas partes.

1. Wrap every tree node title into `<span>`. Then we can CSS-style them on `:hover` and handle clicks exactly on text, because `<span>` width is exactly the text width (unlike without it).
2. Set a handler to the `tree` root node and handle clicks on that `<span>` titles.
1. Envolva o título de cada nó da árvore em um `<span>`. Então podemos estilizá-los com CSS no `:hover` e tratar cliques exatamente no texto, porque a largura do `<span>` é exatamente a largura do texto (diferente de sem ele).
2. Defina um manipulador no nó raiz `tree` e trate cliques nesses títulos `<span>`.
Original file line number Diff line number Diff line change
Expand Up @@ -17,60 +17,60 @@
<body>

<ul class="tree" id="tree">
<li>Animals
<li>Animais
<ul>
<li>Mammals
<li>Mamíferos
<ul>
<li>Cows</li>
<li>Donkeys</li>
<li>Dogs</li>
<li>Tigers</li>
<li>Vacas</li>
<li>Burros</li>
<li>Cachorros</li>
<li>Tigres</li>
</ul>
</li>
<li>Other
<li>Outros
<ul>
<li>Snakes</li>
<li>Birds</li>
<li>Lizards</li>
<li>Cobras</li>
<li>Pássaros</li>
<li>Lagartos</li>
</ul>
</li>
</ul>
</li>
<li>Fishes
<li>Peixes
<ul>
<li>Aquarium
<li>Aquário
<ul>
<li>Guppy</li>
<li>Angelfish</li>
<li>Peixe-anjo</li>
</ul>
</li>
<li>Sea
<li>Mar
<ul>
<li>Sea trout</li>
<li>Truta marinha</li>
</ul>
</li>
</ul>
</li>
</ul>

<script>
// move all text into <span>
// they occupy exactly the place necessary for the text,
// move todo o texto para <span>
// eles ocupam exatamente o espaço necessário para o texto,
for (let li of tree.querySelectorAll('li')) {
let span = document.createElement('span');
li.prepend(span);
span.append(span.nextSibling); // move the text node into span
span.append(span.nextSibling); // move o nó de texto para dentro do span
}

// catch clicks on whole tree
// captura cliques na árvore inteira
tree.onclick = function(event) {

if (event.target.tagName != 'SPAN') {
return;
}

let childrenContainer = event.target.parentNode.querySelector('ul');
if (!childrenContainer) return; // no children
if (!childrenContainer) return; // sem filhos

childrenContainer.hidden = !childrenContainer.hidden;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,36 @@
<body>

<ul class="tree" id="tree">
<li>Animals
<li>Animais
<ul>
<li>Mammals
<li>Mamíferos
<ul>
<li>Cows</li>
<li>Donkeys</li>
<li>Dogs</li>
<li>Tigers</li>
<li>Vacas</li>
<li>Burros</li>
<li>Cachorros</li>
<li>Tigres</li>
</ul>
</li>
<li>Other
<li>Outros
<ul>
<li>Snakes</li>
<li>Birds</li>
<li>Lizards</li>
<li>Cobras</li>
<li>Pássaros</li>
<li>Lagartos</li>
</ul>
</li>
</ul>
</li>
<li>Fishes
<li>Peixes
<ul>
<li>Aquarium
<li>Aquário
<ul>
<li>Guppy</li>
<li>Angelfish</li>
<li>Peixe-anjo</li>
</ul>
</li>
<li>Sea
<li>Mar
<ul>
<li>Sea trout</li>
<li>Truta marinha</li>
</ul>
</li>
</ul>
Expand Down
10 changes: 5 additions & 5 deletions 2-ui/2-events/03-event-delegation/2-sliding-tree/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ importance: 5

---

# Tree menu
# Menu em árvore

Create a tree that shows/hides node children on click:
Crie uma árvore que mostra/oculta os filhos de um nó ao clicar:

[iframe border=1 src="solution"]

Requirements:
Requisitos:

- Only one event handler (use delegation)
- A click outside the node title (on an empty space) should not do anything.
- Apenas um manipulador de evento (use delegação)
- Um clique fora do título do nó (em um espaço vazio) não deve fazer nada.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<table id="grid">
<thead>
<tr>
<th data-type="number">Age</th>
<th data-type="string">Name</th>
<th data-type="number">Idade</th>
<th data-type="string">Nome</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -59,10 +59,10 @@
if (e.target.tagName != 'TH') return;

let th = e.target;
// if TH, then sort
// cellIndex is the number of th:
// 0 for the first column
// 1 for the second column, etc
// se for TH, então ordena
// cellIndex é o número do th:
// 0 para a primeira coluna
// 1 para a segunda coluna, etc
sortGrid(th.cellIndex, th.dataset.type);
};

Expand All @@ -71,7 +71,7 @@

let rowsArray = Array.from(tbody.rows);

// compare(a, b) compares two rows, need for sorting
// compare(a, b) compara duas linhas, necessário para a ordenação
let compare;

switch (type) {
Expand All @@ -87,7 +87,7 @@
break;
}

// sort
// ordena
rowsArray.sort(compare);

tbody.append(...rowsArray);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<table id="grid">
<thead>
<tr>
<th data-type="number">Age</th>
<th data-type="string">Name</th>
<th data-type="number">Idade</th>
<th data-type="string">Nome</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -54,7 +54,7 @@
</table>

<script>
// ...your code...
// ...seu código...
</script>

</body>
Expand Down
18 changes: 9 additions & 9 deletions 2-ui/2-events/03-event-delegation/3-sortable-table/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ importance: 4

---

# Sortable table
# Tabela ordenável

Make the table sortable: clicks on `<th>` elements should sort it by corresponding column.
Faça a tabela ser ordenável: cliques nos elementos `<th>` devem ordená-la pela coluna correspondente.

Each `<th>` has the type in the attribute, like this:
Cada `<th>` tem o tipo no atributo, assim:

```html
<table id="grid">
<thead>
<tr>
*!*
<th data-type="number">Age</th>
<th data-type="string">Name</th>
<th data-type="number">Idade</th>
<th data-type="string">Nome</th>
*/!*
</tr>
</thead>
Expand All @@ -32,12 +32,12 @@ Each `<th>` has the type in the attribute, like this:
</table>
```

In the example above the first column has numbers, and the second one -- strings. The sorting function should handle sort according to the type.
No exemplo acima, a primeira coluna tem números, e a segunda -- strings. A função de ordenação deve tratar a ordenação de acordo com o tipo.

Only `"string"` and `"number"` types should be supported.
Só os tipos `"string"` e `"number"` devem ser suportados.

The working example:
O exemplo funcional:

[iframe border=1 src="solution" height=190]

P.S. The table can be big, with any number of rows and columns.
P.S. A tabela pode ser grande, com qualquer número de linhas e colunas.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<style>
body {
height: 2000px;
/* make body scrollable, the tooltip should work after the scroll */
/* torna o body rolável, a tooltip deve funcionar depois da rolagem */
}

.tooltip {
Expand All @@ -28,10 +28,10 @@
<p>LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa</p>
<p>LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa</p>

<button data-tooltip="the tooltip is longer than the element">Short button</button>
<button data-tooltip="HTML<br>tooltip">One more button</button>
<button data-tooltip="a tooltip é mais longa que o elemento">Botão curto</button>
<button data-tooltip="tooltip<br>em HTML">Mais um botão</button>

<p>Scroll the page to make buttons appear on the top, check if the tooltips show up correctly.</p>
<p>Role a página para fazer os botões aparecerem no topo, verifique se as tooltips aparecem corretamente.</p>


<script>
Expand All @@ -40,25 +40,25 @@
document.onmouseover = function(event) {
let target = event.target;

// if we have tooltip HTML...
// se tivermos o HTML da tooltip...
let tooltipHtml = target.dataset.tooltip;
if (!tooltipHtml) return;

// ...create the tooltip element
// ...cria o elemento da tooltip

tooltipElem = document.createElement('div');
tooltipElem.className = 'tooltip';
tooltipElem.innerHTML = tooltipHtml;
document.body.append(tooltipElem);

// position it above the annotated element (top-center)
// posiciona acima do elemento anotado (centralizado no topo)
let coords = target.getBoundingClientRect();

let left = coords.left + (target.offsetWidth - tooltipElem.offsetWidth) / 2;
if (left < 0) left = 0; // don't cross the left window edge
if (left < 0) left = 0; // não cruza a borda esquerda da janela

let top = coords.top - tooltipElem.offsetHeight - 5;
if (top < 0) { // if crossing the top window edge, show below instead
if (top < 0) { // se cruzar a borda superior da janela, mostra abaixo
top = coords.top + target.offsetHeight + 5;
}

Expand Down
Loading