|
1 |
| -# Interaction: alert, prompt, confirm |
| 1 | +# تعاملی: آلِرت، پِرامت، کانفرم |
| 2 | +همانطور که از مرورگر به عنوان محیط آزمایشی خودمان استفده میکنیم، بگذارید چندتایی تابع تعاملی را بررسی کنیم: `alert`، `prompt` و `confirm`. |
2 | 3 |
|
3 |
| -As we'll be using the browser as our demo environment, let's see a couple of functions to interact with the user: `alert`, `prompt` and `confirm`. |
| 4 | +## آلِرت |
4 | 5 |
|
5 |
| -## alert |
| 6 | +این یکی را قبلاً هم دیدهایم. یک پیغام نمایش میدهد و صبر میکند تا کاربر دکمهٔ «OK» را بزند. |
6 | 7 |
|
7 |
| -This one we've seen already. It shows a message and waits for the user to press "OK". |
8 |
| - |
9 |
| -For example: |
| 8 | +برای مثال: |
10 | 9 |
|
11 | 10 | ```js run
|
12 | 11 | alert("Hello");
|
13 | 12 | ```
|
14 | 13 |
|
15 |
| -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". |
| 14 | +این پنجرهٔ کوچک همراه با پیغام یک *modal window* است. کلمهٔ «modal» به معنای آن است که بازدیدکننده نمیتواند با بقیهٔ صفحه تعامل کند، دکمههای دیگر را بزند و یا غیره، تا زمانی که با پنجرهٔ بازشده کارش تمام شده باشد. در این مورد خاص -- تا زمانی که دکمهٔ «OK» را بزند. |
16 | 15 |
|
17 |
| -## prompt |
| 16 | +## پِرامت |
18 | 17 |
|
19 |
| -The function `prompt` accepts two arguments: |
| 18 | +تابع `primpt` دو پارامتر دارد: |
20 | 19 |
|
21 | 20 | ```js no-beautify
|
22 | 21 | result = prompt(title, [default]);
|
23 | 22 | ```
|
24 | 23 |
|
25 |
| -It shows a modal window with a text message, an input field for the visitor, and the buttons OK/Cancel. |
| 24 | +این تابع یک پنجرهٔ modal همراه با یک پیغام، یک فیلد ورودی برای بازدیدکننده، و دکمههای «OK/Cancel» را نمایش میدهد. |
26 | 25 |
|
27 | 26 | `title`
|
28 |
| -: The text to show the visitor. |
| 27 | +: پیغامی که به کاربر نمایش داده میشود. |
29 | 28 |
|
30 | 29 | `default`
|
31 |
| -: An optional second parameter, the initial value for the input field. |
| 30 | +: یک پارامتر دوم اختیاری، مقدار اولیه برای فیلد ورودی. |
32 | 31 |
|
33 |
| -```smart header="The square brackets in syntax `[...]`" |
34 |
| -The square brackets around `default` in the syntax above denote that the parameter is optional, not required. |
| 32 | +```smart header="براکت های در سینتکس `[...]`" |
| 33 | +براکتهای اطراف `default`در سینتکس بالا اختیاری بودن پارامتر را مشخص میکند. |
35 | 34 | ```
|
36 | 35 |
|
37 |
| -The visitor can type something in the prompt input field and press OK. Then we get that text in the `result`. Or they can cancel the input by pressing Cancel or hitting the `key:Esc` key, then we get `null` as the `result`. |
| 36 | +بازدیدکننده میتواند چیزی را در فیلد ورودی پِرامت تایپ کند و دکمهٔ «OK» را بزند. سپس ما متن را در `result` دریافت میکنیم. یا بازکننده میتواند با زدن دکمهٔ «Cancel» یا فشردن `key:Esc` ورودی را کنسل کند، |
38 | 37 |
|
39 |
| -The call to `prompt` returns the text from the input field or `null` if the input was canceled. |
| 38 | +تابع `prompt` متن دریافتی از فیلد ورودی و یا `null` در صورت کنسل شدن را بر میگرداند. |
40 | 39 |
|
41 |
| -For instance: |
| 40 | +برای مثال: |
42 | 41 |
|
43 | 42 | ```js run
|
44 | 43 | let age = prompt('How old are you?', 100);
|
45 | 44 |
|
46 | 45 | alert(`You are ${age} years old!`); // You are 100 years old!
|
47 | 46 | ```
|
48 | 47 |
|
49 |
| -````warn header="In IE: always supply a `default`" |
50 |
| -The second parameter is optional, but if we don't supply it, Internet Explorer will insert the text `"undefined"` into the prompt. |
| 48 | +````warn header="در اینترنت اکسپلورر: همیشه `default` را تعریف کنید." |
| 49 | +پارامتر دوم اختیاری است، اما اگر آن را تعریف نکنیم، اینترنت اکسپلورر متن `"undefined"` را درون آن قرار میدهد. |
51 | 50 |
|
52 |
| -Run this code in Internet Explorer to see: |
| 51 | +کد زیر را در اینترنت اکسپلورر اجرا کنید تا ببینید: |
53 | 52 |
|
54 | 53 | ```js run
|
55 | 54 | let test = prompt("Test");
|
56 | 55 | ```
|
57 | 56 |
|
58 |
| -So, for prompts to look good in IE, we recommend always providing the second argument: |
| 57 | +پس، برای خوب به نظر رسیدن پِرامتها در اینترنت اکسپلورر، ما پیشنهاد میکنیم همیشه پارامتر دوم را تعریف کنید: |
59 | 58 |
|
60 | 59 | ```js run
|
61 | 60 | let test = prompt("Test", ''); // <-- for IE
|
62 | 61 | ```
|
63 | 62 | ````
|
64 | 63 |
|
65 |
| -## confirm |
| 64 | +## کانفرم |
66 | 65 |
|
67 |
| -The syntax: |
| 66 | +سینتکس کد: |
68 | 67 |
|
69 | 68 | ```js
|
70 | 69 | result = confirm(question);
|
71 | 70 | ```
|
72 | 71 |
|
73 |
| -The function `confirm` shows a modal window with a `question` and two buttons: OK and Cancel. |
| 72 | +تابع `confirm` یک پنجرهٔ modal همراه با یک `سوال` و دو دکمهٔ OK و Cancel نمایش میدهد. |
74 | 73 |
|
75 |
| -The result is `true` if OK is pressed and `false` otherwise. |
| 74 | +در صورتی که OK کلیک شود، نتیجه `true` و در غیر اینصورت، نتیجه `false` خواهد شد. |
76 | 75 |
|
77 |
| -For example: |
| 76 | +برای مثال: |
78 | 77 |
|
79 | 78 | ```js run
|
80 | 79 | let isBoss = confirm("Are you the boss?");
|
81 | 80 |
|
82 | 81 | alert( isBoss ); // true if OK is pressed
|
83 | 82 | ```
|
84 | 83 |
|
85 |
| -## Summary |
| 84 | +## خلاصه |
86 | 85 |
|
87 |
| -We covered 3 browser-specific functions to interact with visitors: |
| 86 | +ما ۳ تابعٔ خاص مرورگر را که از طریق آنها میتوان با کاربر تعامل کرد را بررسی کردیم: |
88 | 87 |
|
89 | 88 | `alert`
|
90 |
| -: shows a message. |
| 89 | +: نمایش یک پیغام. |
91 | 90 |
|
92 | 91 | `prompt`
|
93 |
| -: shows a message asking the user to input text. It returns the text or, if Cancel button or `key:Esc` is clicked, `null`. |
| 92 | +: نمایش یک پیغام و درخواست از کاربر برای وارد کردن متن. این تابع متن را و یا اگر دکمهٔ Cancel یا `key:Esc` زده شود `null` را بر میگرداند. |
94 | 93 |
|
95 | 94 | `confirm`
|
96 |
| -: shows a message and waits for the user to press "OK" or "Cancel". It returns `true` for OK and `false` for Cancel/`key:Esc`. |
| 95 | +: نمایش یک پیغام و منتظرماندن برای کاربر تا دکمهٔ «OK» یا «Cancel» را فشار دهد. این تابع برای OK `true` و برای Cancel/`key:Esc` `false` را بر میگرداند. |
97 | 96 |
|
98 |
| -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. |
| 97 | +همهٔ این توابع، مُدال هستند: آنها اجرای اسکریپت را متوقف میکنند و به بازدیدکننده اجازه تعامل با بقیهٔ صفحه را تا زمانی که پنجره بسته شود نمیدهند. |
99 | 98 |
|
100 |
| -There are two limitations shared by all the methods above: |
| 99 | +دو محدودیت دربارهٔ همهٔ تابعهای بالا وجود دارد: |
101 | 100 |
|
102 |
| -1. The exact location of the modal window is determined by the browser. Usually, it's in the center. |
103 |
| -2. The exact look of the window also depends on the browser. We can't modify it. |
| 101 | +1. مکان دقیق پنجرهٔ modal توسط مرورگر تعیین میشود. معمولاً در وسط صفحه قرار دارد. |
| 102 | +2. ظاهر دقیق پنجره نیز توسط مرورگر تعیین میشود. ما نمیتوانیم آن را تغییر دهیم. |
104 | 103 |
|
105 |
| -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. |
| 104 | +این بهاییست که برای سادگی میپردازیم. راههای دیگری برای نمایش پنجرههای بهتر و غنیتر برای تعامل با بازدیدکننده نیز وجود دارد، ولی اگر «زرق و برق» برایتان مهم نیست، این توابع کار را به خوبی انجام میدهند. |
0 commit comments