|
1 |
| -# Interaction: alert, prompt, confirm |
| 1 | +# Interakcija: alert, prompt, confirm |
2 | 2 |
|
3 |
| -In this part of the tutorial we cover JavaScript language "as is", without environment-specific tweaks. |
| 3 | +Šioje pamokų dalyje kalbėsime apie JavaScript kalbą "tokia kokia ji yra", be aplinkai būdingų pataisymų. |
4 | 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`. |
| 5 | +Bet vis dar naudosime naršykles kaip mūsų pavyzdinę aplinką, tad turėtume žinoti bent kelias vartotojo sąsajos (ang. user-interface) savybes. Šiame skyriuje susipažinsime su šiomis naršyklės funkcijomis `alert`, `prompt` ir `confirm`. |
6 | 6 |
|
7 | 7 | ## alert
|
8 | 8 |
|
9 |
| -Syntax: |
| 9 | +Sintaksė: |
10 | 10 |
|
11 | 11 | ```js
|
12 | 12 | alert(message);
|
13 | 13 | ```
|
14 | 14 |
|
15 |
| -This shows a message and pauses script execution until the user presses "OK". |
| 15 | +Parodo žinutę ir sustabdo skriptą iki kol vartotojas paspaus "OK". |
16 | 16 |
|
17 |
| -For example: |
| 17 | +Pavyzdžiui: |
18 | 18 |
|
19 | 19 | ```js run
|
20 |
| -alert("Hello"); |
| 20 | +alert("Labas"); |
21 | 21 | ```
|
22 | 22 |
|
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". |
| 23 | +Miniatiūrinis langelis su žinute yra vadinamas *modaliniu langeliu* (ang. *modal window*). Žodis "modalinis" reiškia, kad lankytojas negali naudotis likusiu puslapiu, spausti kitų mygtukų ir t.t. kol nesusitvarkė su langeliu. Šiuo atveju -- iki kol paspaus "OK". |
24 | 24 |
|
25 | 25 | ## prompt
|
26 | 26 |
|
27 |
| -The function `prompt` accepts two arguments: |
| 27 | +Funkcija `prompt` priima du argumentus: |
28 | 28 |
|
29 | 29 | ```js no-beautify
|
30 | 30 | result = prompt(title, [default]);
|
31 | 31 | ```
|
32 | 32 |
|
33 |
| -It shows a modal window with a text message, an input field for the visitor, and the buttons OK/Cancel. |
| 33 | +Parodo modalinį langelį su paprasta tekstine žinute, įvesties laukeliu lankytojui ir mygtukus OK/Cancel. |
34 | 34 |
|
35 | 35 | `title`
|
36 |
| -: The text to show the visitor. |
| 36 | +: Tekstas, kurį reikės parodyti lankytojui. |
37 | 37 |
|
38 | 38 | `default`
|
39 |
| -: An optional second parameter, the initial value for the input field. |
| 39 | +: Nebūtinas antras parametras, pradinė vertė įvesties laukeliui. |
40 | 40 |
|
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. |
| 41 | +Lankytojas gali ką nors įvesti laukelyje ir paspausti OK. Arba jie gali atšaukti paspausdami Cancel ar klaviatūroje `key:Esc` mygtuką. |
42 | 42 |
|
43 |
| -The call to `prompt` returns the text from the input field or `null` if the input was canceled. |
| 43 | +Iššauktas `prompt` grąžina tekstą iš įvesties laukelio arba `null`, jeigu įvestis buvo atšaukta. |
44 | 44 |
|
45 |
| -For instance: |
| 45 | +Pavyzdžiui: |
46 | 46 |
|
47 | 47 | ```js run
|
48 |
| -let age = prompt('How old are you?', 100); |
| 48 | +let age = prompt('Kiek jums metų?', 100); |
49 | 49 |
|
50 |
| -alert(`You are ${age} years old!`); // You are 100 years old! |
| 50 | +alert(`Jums yra ${age} metų!`); // Jums yra 100 metų! |
51 | 51 | ```
|
52 | 52 |
|
53 |
| -````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. |
| 53 | +````warn header="IE naršyklėje: visada nurodykite `default`" |
| 54 | +Antras parametras nėra būtinas, bet jeigu jo nepateiksite, Internet Explorer įtrauks `"undefined"` į prompt tekstą. |
55 | 55 |
|
56 |
| -Run this code in Internet Explorer to see: |
| 56 | +Norėdami išbandyti, paleiskite šį kodą Internet Explorer naršyklėje: |
57 | 57 |
|
58 | 58 | ```js run
|
59 |
| -let test = prompt("Test"); |
| 59 | +let test = prompt("Testas"); |
60 | 60 | ```
|
61 | 61 |
|
62 |
| -So, for prompts to look good in IE, we recommend always providing the second argument: |
| 62 | +Tad tam, kad prompt visada gerai atrodytų IE, mes rekomenduojame visada pateikti antrą argumentą: |
63 | 63 |
|
64 | 64 | ```js run
|
65 |
| -let test = prompt("Test", ''); // <-- for IE |
| 65 | +let test = prompt("Testas", ''); // <-- skirta IE |
66 | 66 | ```
|
67 | 67 | ````
|
68 | 68 |
|
69 | 69 | ## confirm
|
70 | 70 |
|
71 |
| -The syntax: |
| 71 | +Sintaksė: |
72 | 72 |
|
73 | 73 | ```js
|
74 | 74 | result = confirm(question);
|
75 | 75 | ```
|
76 | 76 |
|
77 |
| -The function `confirm` shows a modal window with a `question` and two buttons: OK and Cancel. |
| 77 | +Funkcija `confirm` parodo modalinį langelį su `question` (klausimu) ir dviem mygtukais: OK ir Cancel. |
78 | 78 |
|
79 |
| -The result is `true` if OK is pressed and `false` otherwise. |
| 79 | +Rezultatas būna `true`, jeigu paspaudžiamas OK ir `false` kitu atveju. |
80 | 80 |
|
81 |
| -For example: |
| 81 | +Pavyzdžiui: |
82 | 82 |
|
83 | 83 | ```js run
|
84 |
| -let isBoss = confirm("Are you the boss?"); |
| 84 | +let isBoss = confirm("Ar tu esi bosas?"); |
85 | 85 |
|
86 |
| -alert( isBoss ); // true if OK is pressed |
| 86 | +alert( isBoss ); // true, jeigu paspaudžiamas OK |
87 | 87 | ```
|
88 | 88 |
|
89 |
| -## Summary |
| 89 | +## Santrauka |
90 | 90 |
|
91 |
| -We covered 3 browser-specific functions to interact with visitors: |
| 91 | +Mes aptarėme 3 naršyklei būdingas funkcijas skirtas bendrauti su lankytojais: |
92 | 92 |
|
93 | 93 | `alert`
|
94 |
| -: shows a message. |
| 94 | +: parodo žinutę. |
95 | 95 |
|
96 | 96 | `prompt`
|
97 |
| -: shows a message asking the user to input text. It returns the text or, if Cancel button or `key:Esc` is clicked, `null`. |
| 97 | +: parodo žinutę prašydamas vartotojo įvesti tekstą. Grąžina tekstą arba, jeigu paspaudžiamas Cancel ar `key:Esc` grąžinamas `null`. |
98 | 98 |
|
99 | 99 | `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`. |
| 100 | +: parodo žinutę ir laukia kol lankytojas paspaus "OK" arba "Cancel". Grąžina `true` kai OK ir `false` kai Cancel/`key:Esc`. |
101 | 101 |
|
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. |
| 102 | +Visi šie veiksmai yra modaliniai: jie sustabdo skripto vykdymą ir neleidžia lankytojams naudotis likusiu puslapiu kol langelis nėra uždaromas. |
103 | 103 |
|
104 |
| -There are two limitations shared by all the methods above: |
| 104 | +Visus anksčiau minėtus metodus sieja du apribojimai: |
105 | 105 |
|
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. |
| 106 | +1. Naršyklė nustato tikslią modalinio langelio vietą. Dažniausiai tai yra centras. |
| 107 | +2. Tiksli langelio išvaizda taip pat priklauso nuo naršyklės. Mes jo pakeisti negalime. |
108 | 108 |
|
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. |
| 109 | +Tokia yra paprastumo kaina. Yra daug kitų būdų parodyti gražesnius langelius ir naudoti puikesnį bendravimą su lankytojais, bet jeigu nėra labai svarbu įmantrumai esami metodai veikia kuo puikiausiai. |
0 commit comments