-
Notifications
You must be signed in to change notification settings - Fork 183
Interaction: alert, prompt, confirm #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tarasyyyk
merged 6 commits into
javascript-tutorial:master
from
Zim123:1_02_09_alerts_prompt_confirm
May 31, 2019
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
90945ad
started new chapter translation
Zim123 52f58e3
finished translation
Zim123 f002e0c
fixed merge conflicts
Zim123 9474456
add missing translation
tarasyyyk a6b12a7
some corrections
Zim123 a2af800
Merge branch '1_02_09_alerts_prompt_confirm' of https://github.com/Zi…
Zim123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,109 +1,109 @@ | ||
| # Interaction: alert, prompt, confirm | ||
| # Взаємодія: alert, prompt, confirm | ||
|
|
||
| In this part of the tutorial we cover JavaScript language "as is", without environment-specific tweaks. | ||
| Ця частина підручника спрямована на розгляд JavaScript "як є", без спеціальних налаштувань середовища. | ||
|
|
||
| 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`. | ||
| Але ми як і раніше будемо використовувати браузер як середовище для демонстрацій, тому ми повинні знати принаймні деякі з його функцій інтерфейсу користувача. У цьому розділі ми ознайомимося з функціями браузера `alert`, `prompt` та `confirm`. | ||
|
|
||
| ## alert | ||
|
|
||
| Syntax: | ||
| Синтаксис: | ||
|
|
||
| ```js | ||
| alert(message); | ||
| ``` | ||
|
|
||
| This shows a message and pauses script execution until the user presses "OK". | ||
| Ця функція показує повідомлення та призупиняє виконання скрипта поки користувач не натисне кнопку "OK". | ||
|
|
||
| For example: | ||
| Наприклад: | ||
|
|
||
| ```js run | ||
| alert("Hello"); | ||
| alert("Привіт"); | ||
| ``` | ||
|
|
||
| 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". | ||
| Міні-вікно з повідомленням називається *модальним вікном*. Слово "модальний" означає, що відвідувач не може взаємодіяти з іншою частиною сторінки, натискати інші кнопки, тощо, поки він не завершить операції з вікном. У цьому випадку -- поки він не натисне "OK". | ||
|
|
||
| ## prompt | ||
|
|
||
| The function `prompt` accepts two arguments: | ||
| Функція `prompt` приймає два аргументи: | ||
|
|
||
| ```js no-beautify | ||
| result = prompt(title, [default]); | ||
| ``` | ||
|
|
||
| It shows a modal window with a text message, an input field for the visitor, and the buttons OK/CANCEL. | ||
| Вона показує модальне вікно з текстовим повідомленням, полем введення для відвідувача, та кнопками OK/CANCEL. | ||
|
|
||
| `title` | ||
| : The text to show the visitor. | ||
| : Текст, який буде видображатися для відвідувача. | ||
|
|
||
| `default` | ||
| : An optional second parameter, the initial value for the input field. | ||
| : Необов'язковий другий параметр, початкове значення для поля введення. | ||
|
|
||
| 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. | ||
| Відвідувач може ввести щось у поле введення запиту і натиснути OK. Або він може скасувати введення, натиснувши CANCEL або натиснувши клавішу `key:Esc`. | ||
|
|
||
| The call to `prompt` returns the text from the input field or `null` if the input was canceled. | ||
| Виклик`prompt` повертає текст з поля введення або `null`, якщо введення було скасоване. | ||
Zim123 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| For instance: | ||
| Наприклад: | ||
|
|
||
| ```js run | ||
| let age = prompt('How old are you?', 100); | ||
| let age = prompt('Скільки вам років?', 100); | ||
|
|
||
| alert(`You are ${age} years old!`); // You are 100 years old! | ||
| alert(`Вам ${age} років!`); // Вам 100 років! | ||
| ``` | ||
|
|
||
| ````warn header="In IE: always supply a `default`" | ||
| The second parameter is optional, but if we don't supply it, Internet Explorer will insert the text `"undefined"` into the prompt. | ||
| ````warn header="В IE: завжди вказуйте початкове значення `default`" | ||
| Другий параметр є необов'язковим, але якщо ми не надамо його, Internet Explorer вставить у рядок текст `"undefined"`. | ||
|
|
||
| Run this code in Internet Explorer to see: | ||
| Запустіть цей код в Internet Explorer, щоб побачити: | ||
|
|
||
| ```js run | ||
| let test = prompt("Test"); | ||
| ``` | ||
|
|
||
| So, for prompts to look good in IE, we recommend always providing the second argument: | ||
| Отже, щоб модальні вікна prompts добре виглядали у IE, ми рекомендуємо завжди надавати другий аргумент: | ||
|
|
||
| ```js run | ||
| let test = prompt("Test", ''); // <-- for IE | ||
| let test = prompt("Test", ''); // <-- для IE | ||
| ``` | ||
| ```` | ||
| ## confirm | ||
| The syntax: | ||
| Синтаксис: | ||
| ```js | ||
| result = confirm(question); | ||
| ``` | ||
| The function `confirm` shows a modal window with a `question` and two buttons: OK and CANCEL. | ||
| Функція `confirm` показує модальне вікно з `питанням` та двома кнопками: OK та CANCEL. | ||
| The result is `true` if OK is pressed and `false` otherwise. | ||
| Результат `true` якщо натиснути кнопку OK, інакше `false`. | ||
| For example: | ||
| Наприклад: | ||
| ```js run | ||
| let isBoss = confirm("Are you the boss?"); | ||
| let isBoss = confirm("Ви бос?"); | ||
| alert( isBoss ); // true if OK is pressed | ||
| alert( isBoss ); // true якщо натуснута OK | ||
| ``` | ||
| ## Summary | ||
| ## Підсумки | ||
| We covered 3 browser-specific functions to interact with visitors: | ||
| Ми вивчили 3 специфічні для браузера функції, для взаємодії з відвідувачами: | ||
| `alert` | ||
| : shows a message. | ||
| : показує повідомлення. | ||
| `prompt` | ||
| : shows a message asking the user to input text. It returns the text or, if CANCEL or `key:Esc` is clicked, `null`. | ||
| : показує повідомлення з проханням ввести текст. Вона повертає текст або `null`, якщо натиснуті CANCEL або `key:Esc`. | ||
| `confirm` | ||
| : shows a message and waits for the user to press "OK" or "CANCEL". It returns `true` for OK and `false` for CANCEL/`key:Esc`. | ||
| : показує повідомлення і чекає, коли користувач натисне "OK" або "CANCEL". Вона повертає `true` для OK та `false` для CANCEL/`key:Esc`. | ||
| 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. | ||
| Всі ці методи є модальними: вони призупиняють виконання скриптів та не дозволяють відвідувачам взаємодіяти з рештою сторінки, поки вікно не буде відхилено. | ||
| There are two limitations shared by all the methods above: | ||
| Існують два обмеження, пов'язані з усіма методами вище: | ||
| 1. The exact location of the modal window is determined by the browser. Usually, it's in the center. | ||
| 2. The exact look of the window also depends on the browser. We can't modify it. | ||
| 1. Точне розташування модального вікна визначається браузером. Зазвичай це в центрі. | ||
| 2. Точний вигляд вікна також залежить від браузера. Ми не можемо його змінити. | ||
| 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. | ||
| Це ціна за простоту. Є й інші способи показувати приємніші вікна та богатшу взаємодію з відвідувачем, але якщо "навороти" не мають значення, то ці методи працюють дуже добре. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.