Skip to content

Translate 'Interaction: alert, prompt, confirm' page #35

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
merged 2 commits into from
Nov 6, 2019
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
@@ -1,11 +1,11 @@
JavaScript-code:
Kod JavaScript:

```js demo run
let name = prompt("What is your name?", "");
let name = prompt("Jak masz na imię?", "");
alert(name);
```

The full page:
Cała strona:

```html
<!DOCTYPE html>
Expand All @@ -15,7 +15,7 @@ The full page:
<script>
'use strict';

let name = prompt("What is your name?", "");
let name = prompt("Jak masz na imię?", "");
alert(name);
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ importance: 4

---

# A simple page
# Prost strona

Create a web-page that asks for a name and outputs it.
Stwórz prostą stronę, która zapyta użytkownika o imię, a następnie wyświeli je.

[demo]
76 changes: 38 additions & 38 deletions 1-js/02-first-steps/09-alert-prompt-confirm/article.md
Original file line number Diff line number Diff line change
@@ -1,109 +1,109 @@
# Interaction: alert, prompt, confirm
# Interakcje: alert, prompt, confirm

In this part of the tutorial we cover JavaScript language "as is", without environment-specific tweaks.
W tej części poradnika przedstawimy język JavaScript w podstawowej formie, bez żadnych ulepszeń dla danego środowiska.

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`.
Nadal będziemy używać przeglądarki jako domyślnego środowiska, więc powinniśmy znać przynajmniej kilka funkcji interfejsu przeglądarki. W tym rozdziale, zaznajomimy się z funkcjami dostępnymi w przeglądarce: `alert`, `prompt` and `confirm`.

## alert

Syntax:
Składnia:

```js
alert(message);
```

This shows a message and pauses script execution until the user presses "OK".
Funkcja `alert` wyświetla zawartość zmiennej `message` i wstrzymuje wykonywanie skryptu do czasu, kiedy użytkownik kliknie "OK".

For example:
Na przykład:

```js run
alert("Hello");
alert("Witaj");
```

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".
Pojawi się niewielkie okno z wiadomością, które nazywamy *oknem modalnym*. Słowo "modalny" oznacza, że użytkownik nie może wejść w interakcję z pozostałą treścią strony czy też z innymi przyciskami i tak dalej, dopóki nie zakończy interakcji z oknem. W tym przypadku -- do czasu kliknięcia *OK*.

## prompt

The function `prompt` accepts two arguments:
Funkcja `prompt` przyjmuje dwa argumenty:

```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.
Funkcja `prompt` wyświetla okno z wiadomością, pole tekstowe do uzupełnienia przez użytkownika oraz przyciski *OK/Anuluj*.

`title`
: The text to show the visitor.
: Tekst, który zostanie wyświetlony użytkownikowi.

`default`
: An optional second parameter, the initial value for the input field.
: Opcjonalny drugi parametr, wartość początkowa dla pola tekstowego.

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.
Użytkownik może wpisać tekst do pola tekstowego i zatwierdzić przyciskiem *OK*. Może także anulować operację, klikając przycisk *Anuluj* lub wciskając klawisz `key:Esc`.

The call to `prompt` returns the text from the input field or `null` if the input was canceled.
Wywołanie funkcji `prompt` zwraca tekst wpisany do pola tekstowego lub wartość `null`, w przypadku gdy użytkownik anulował akcję.

For instance:
Na przykład:

```js run
let age = prompt('How old are you?', 100);
let age = prompt('Ile masz lat?', 100);

alert(`You are ${age} years old!`); // You are 100 years old!
alert(`Masz ${age} lat!`); // Masz 100 lat!
```

````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="W IE: zawsze dodawaj parametr `default`"
Drugi parametr jest, co prawda, opcjonalny, lecz w przypadku braku dostarczenia go w przeglądarce Internet Explorer, do pola tekstowego zostanie wstawiony napis `"undefined"`.

Run this code in Internet Explorer to see:
Aby się o tym przekonać, uruchom poniższy kod w Internet Explorerze:

```js run
let test = prompt("Test");
```

So, for prompts to look good in IE, we recommend always providing the second argument:
Dlatego do poprawnego działania funkcji `prompt` w IE radzimy zawsze dodawać drugi argument:

```js run
let test = prompt("Test", ''); // <-- for IE
let test = prompt("Test", ''); // <-- dla IE
```
````

## confirm

The syntax:
Składnia:

```js
result = confirm(question);
```

The function `confirm` shows a modal window with a `question` and two buttons: OK and Cancel.
Funkcja `confirm` wyświetla okno modalne z pytaniem zawartym w `question` i dwoma przyciskami: *OK* i *Anuluj*.

The result is `true` if OK is pressed and `false` otherwise.
Po naciśnięciu *OK* otrzymujemy wartość `true`, w przeciwnym wypadku `false`.

For example:
Na przykład:

```js run
let isBoss = confirm("Are you the boss?");
let isBoss = confirm("Czy jesteś szefem?");

alert( isBoss ); // true if OK is pressed
alert( isBoss ); // true, jeżeli kliknięto na "OK"
```

## Summary
## Podsumowanie

We covered 3 browser-specific functions to interact with visitors:
Omówiliśmy 3 funkcje dostępne w przeglądarkach, służące do interakcji z użytkownikami:

`alert`
: shows a message.
: wyświetla wiadomość.

`prompt`
: shows a message asking the user to input text. It returns the text or, if Cancel button or `key:Esc` is clicked, `null`.
: wyświetla wiadomość z polem tekstowym. Zwraca wprowadzony przez użytkownika tekst lub wartość `null` w przypadku anulowania poprzez kliknięcie przycisku *Anuluj* albo użycie klawisza `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`.
: wyświetla wiadomość i oczekuje na użytkownika, który może użyć przycisku *OK* lub *Anuluj*. Zwraca `true` dla *OK* albo `false` *Anuluj*/`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.
Wszystkie metody wyświetlają okna: wstrzymują wykonywanie skryptu i nie pozwalają użytkownikowi na dalszą interakcję ze stroną do czasu zamknięcia okna.

There are two limitations shared by all the methods above:
Istnieją dwa ograniczenia związane z powyższymi metodami:

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. Dokładna lokalizacja okna jest ustalana przez przeglądarkę. Zazwyczaj pojawia się pośrodku okna przeglądarki.
2. Wygląd okna także zależy od przeglądarki. Nie możemy go zmodyfikować.

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.
Taka jest cena dla tego typu ułatwień. Istnieją inne możliwości na wyświetlanie lepszych okien i rozszerzenie interakcji z użytkownikiem, lecz jeżeli nie zależy nam na "wodotryskach", te metody w zupełności wystarczą.