|
1 |
| -# Interaction: alert, prompt, confirm |
| 1 | +# Interação: alert, prompt, confirm |
2 | 2 |
|
3 |
| -This part of the tutorial aims to cover JavaScript "as is", without environment-specific tweaks. |
4 |
| - |
5 |
| -But we'll still be using the browser as our demo environment, so we should know at least a few of its user-interface functions. In this chapter, we'll get familiar with the browser functions `alert`, `prompt` and `confirm`. |
| 3 | +Esta parte do tutorial tem como objetivo cobrir o JavaScript "como é ", sem ajustes específicos de ambiente. |
| 4 | +Mas ainda estaremos usando o navegador como nosso ambiente de demostração, portanto devemos conhecer pelo menos algumas de suas funções de interface. Neste capítulo, familiazaremos com as funções do navegador `alert`, `prompt` e `confirm`. |
6 | 5 |
|
7 | 6 | ## alert
|
8 | 7 |
|
9 |
| -Syntax: |
| 8 | +Sintaxe: |
10 | 9 |
|
11 | 10 | ```js
|
12 |
| -alert(message); |
| 11 | +alert(mensagem); |
13 | 12 | ```
|
14 | 13 |
|
15 |
| -This shows a message and pauses script execution until the user presses "OK". |
| 14 | + mostrará uma mensagem até o usuário pressionar "OK". |
16 | 15 |
|
17 |
| -For example: |
| 16 | +Por exemplo: |
18 | 17 |
|
19 | 18 | ```js run
|
20 |
| -alert("Hello"); |
| 19 | +alert("Ola"); |
21 | 20 | ```
|
22 | 21 |
|
23 |
| -The mini-window with the message is called a *modal window*. The word "modal" means that the visitor can't interact with the rest of the page, press other buttons, etc. until they have dealt with the window. In this case -- until they press "OK". |
24 | 22 |
|
| 23 | +A mini-janela com a mensagem é chamada *modal view*. A palavra "modal" significa que o visitante não pode interagir com o resto da página, pressionar outros botões, etc. Até que ele tenha lidado com a janela. Nesse caso -- até pressionar "OK" |
25 | 24 | ## prompt
|
26 | 25 |
|
27 |
| -The function `prompt` accepts two arguments: |
| 26 | +A função `prompt` aceita dois argumentos |
28 | 27 |
|
29 | 28 | ```js no-beautify
|
30 | 29 | result = prompt(title, [default]);
|
31 | 30 | ```
|
32 | 31 |
|
33 |
| -It shows a modal window with a text message, an input field for the visitor, and the buttons OK/CANCEL. |
| 32 | +Mostra uma janela modal com mensagem de texto, um campo de entrada para o visitante, e os botões OK/CANCEL |
| 33 | + |
34 | 34 |
|
35 | 35 | `title`
|
36 |
| -: The text to show the visitor. |
| 36 | +: Texto para ser mostrado ao visitante. |
37 | 37 |
|
38 | 38 | `default`
|
39 |
| -: An optional second parameter, the initial value for the input field. |
| 39 | +: Um parâmetro opcional, valor inicial para o campo de entrada |
| 40 | + |
40 | 41 |
|
41 |
| -The visitor may type something in the prompt input field and press OK. Or they can cancel the input by pressing CANCEL or hitting the `key:Esc` key. |
| 42 | +O visitante pode digitar algo no campo de entrada do prompt e pressionar OK. Ou ele pode cancelar a entrada pressionando CANCEL ou `key:Esc`. |
42 | 43 |
|
43 |
| -The call to `prompt` returns the text from the input field or `null` if the input was canceled. |
| 44 | +A chamada do `prompt` retorna o texto do campo de entrada ou `null` se a entrada foi cancelada. |
44 | 45 |
|
45 |
| -For instance: |
| 46 | +Por exemplo: |
46 | 47 |
|
47 | 48 | ```js run
|
48 |
| -let age = prompt('How old are you?', 100); |
| 49 | +let age = prompt('Qual a sua idade ?', 100); |
49 | 50 |
|
50 |
| -alert(`You are ${age} years old!`); // You are 100 years old! |
| 51 | +alert(`Você tem ${age} anos!`); //Você tem 100 anos! |
51 | 52 | ```
|
52 | 53 |
|
53 | 54 | ````warn header="In IE: always supply a `default`"
|
54 |
| -The second parameter is optional, but if we don't supply it, Internet Explorer will insert the text `"undefined"` into the prompt. |
| 55 | +O segundo parâmetro é opcional, mas se não o fornecermos, Internet Explorer irá inserir o texto `"undefined"` no prompt. |
55 | 56 |
|
56 |
| -Run this code in Internet Explorer to see: |
| 57 | +Execute este código no Internet Explorer para visualizar: |
57 | 58 |
|
58 | 59 | ```js run
|
59 |
| -let test = prompt("Test"); |
| 60 | +let test = prompt("Teste"); |
60 | 61 | ```
|
61 | 62 |
|
62 |
| -So, for prompts to look good in IE, we recommend always providing the second argument: |
| 63 | +portanto, para que os prompts tenham boa aparência no IE, recomendamos sempre fornecer o segundo argumento: |
63 | 64 |
|
64 | 65 | ```js run
|
65 |
| -let test = prompt("Test", ''); // <-- for IE |
| 66 | +let test = prompt("Teste", ''); // <-- para IE |
66 | 67 | ```
|
67 | 68 | ````
|
68 | 69 |
|
69 | 70 | ## confirm
|
70 | 71 |
|
71 |
| -The syntax: |
| 72 | +Sintaxe: |
72 | 73 |
|
73 | 74 | ```js
|
74 | 75 | result = confirm(question);
|
75 | 76 | ```
|
76 | 77 |
|
77 |
| -The function `confirm` shows a modal window with a `question` and two buttons: OK and CANCEL. |
78 |
| -
|
79 |
| -The result is `true` if OK is pressed and `false` otherwise. |
80 |
| -
|
81 |
| -For example: |
| 78 | +A função `confirm` mostra uma janela modal com uma `question` e dois botões: OK e CANCEL. |
| 79 | +O resultado é `true` se OK for pressionado e `false` caso contrário |
| 80 | +Por exemplo: |
82 | 81 |
|
83 | 82 | ```js run
|
84 |
| -let isBoss = confirm("Are you the boss?"); |
| 83 | +let isBoss = confirm("Você é o chefe ?"); |
85 | 84 |
|
86 |
| -alert( isBoss ); // true if OK is pressed |
| 85 | +alert( isBoss ); // true se OK for pressionado |
87 | 86 | ```
|
88 | 87 |
|
89 |
| -## Summary |
| 88 | +## Sumário |
90 | 89 |
|
91 |
| -We covered 3 browser-specific functions to interact with visitors: |
| 90 | +Cobrimos 3 funções específicas do navegador para interagir com o visitante: |
92 | 91 |
|
93 | 92 | `alert`
|
94 |
| -: shows a message. |
| 93 | +: mostra uma mensagem. |
95 | 94 |
|
96 | 95 | `prompt`
|
97 |
| -: shows a message asking the user to input text. It returns the text or, if CANCEL or `key:Esc` is clicked, `null`. |
| 96 | +: mostra uma mensagem pedindo para o usuário inserir texto. Ele retorna o texto ou, se CANCEL ou `key:Esc` for clicado, `null`. |
98 | 97 |
|
99 | 98 | `confirm`
|
100 |
| -: shows a message and waits for the user to press "OK" or "CANCEL". It returns `true` for OK and `false` for CANCEL/`key:Esc`. |
| 99 | +: mostra uma mensagem e espera o usuário pressionar "OK" ou "CANCEL". Ele retorna `true` para OK e `false` para CANCEL/`key:Esc`. |
101 | 100 |
|
102 |
| -All these methods are modal: they pause script execution and don't allow the visitor to interact with the rest of the page until the window has been dismissed. |
| 101 | +Todos esse métodos são modais: eles pausam a execução do script e não permitem o visitante interagir com o resto da página até que a janela seja descartada. |
103 | 102 |
|
104 |
| -There are two limitations shared by all the methods above: |
| 103 | +Existem duas limitações compartilhada entre esses metódos acima: |
105 | 104 |
|
106 |
| -1. The exact location of the modal window is determined by the browser. Usually, it's in the center. |
107 |
| -2. The exact look of the window also depends on the browser. We can't modify it. |
| 105 | +1. A localização exata da janela modal é determinada pelo navegador. Geralmente, está no centro. |
| 106 | +2. A aparência exata da janela também depende do navegador. Nós não podemos modificá-la. |
108 | 107 |
|
109 |
| -That is the price for simplicity. There are other ways to show nicer windows and richer interaction with the visitor, but if "bells and whistles" do not matter much, these methods work just fine. |
| 108 | +Esse é o preço da simplicidade. Existem outras duas maneiras de mostrar janelas mais agradáveis e interações mais ricas com os visitantes, mas se "sinos e assobios" não importam muito, esses métodos funcionam bem. |
0 commit comments