Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5bc5649

Browse files
authoredApr 30, 2022
Merge pull request #66 from otmon76/2.1
2.1
2 parents c0de135 + 6099d25 commit 5bc5649

File tree

6 files changed

+56
-57
lines changed

6 files changed

+56
-57
lines changed
 

‎1-js/02-first-steps/01-hello-world/1-hello-alert/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<body>
55

66
<script>
7-
alert( "I'm JavaScript!" );
7+
alert( "Já jsem JavaScript!" );
88
</script>
99

1010
</body>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
importance: 5
1+
důležitost: 5
22

33
---
44

5-
# Show an alert
5+
# Zobrazte zprávu
66

7-
Create a page that shows a message "I'm JavaScript!".
7+
Vytvořte stránku, která zobrazí zprávu „Já jsem JavaScript!.
88

9-
Do it in a sandbox, or on your hard drive, doesn't matter, just ensure that it works.
9+
Nezáleží na tom, zda to uděláte na pískovišti nebo lokálně, jen se snažte, aby to fungovalo.
1010

1111
[demo src="solution"]
1212

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
alert("I'm JavaScript!");
1+
alert("Já jsem JavaScript!");
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
The HTML code:
1+
HTML kód:
22

33
[html src="index.html"]
44

5-
For the file `alert.js` in the same folder:
5+
Pro soubor `alert.js` ve stejné složce:
66

77
[js src="alert.js"]
8-

‎1-js/02-first-steps/01-hello-world/2-hello-alert-ext/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ importance: 5
22

33
---
44

5-
# Show an alert with an external script
5+
# Zobrazte zprávu pomocí externího skriptu
66

7-
Take the solution of the previous task <info:task/hello-alert>. Modify it by extracting the script content into an external file `alert.js`, residing in the same folder.
7+
Vezměte si řešení předchozí úlohy <info:task/hello-alert>, vytvořte ve stejné složce nový soubor `alert.js` a obsah skriptu přemístěte do něj.
88

9-
Open the page, ensure that the alert works.
9+
Otevřete stránku a ujistěte se, že se zpráva zobrazuje.
Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,87 @@
1-
# Hello, world!
1+
# Ahoj, světe!
22

3-
This part of the tutorial is about core JavaScript, the language itself.
3+
Tato část tutoriálu pojednává o základech JavaScriptu, o samotném jazyce.
44

5-
But we need a working environment to run our scripts and, since this book is online, the browser is a good choice. We'll keep the amount of browser-specific commands (like `alert`) to a minimum so that you don't spend time on them if you plan to concentrate on another environment (like Node.js). We'll focus on JavaScript in the browser in the [next part](/ui) of the tutorial.
5+
Potřebujeme však pracovní prostředí, v němž budeme spouštět skripty. Protože tato kniha je online, prohlížeč je dobrá volba. Budeme však udržovat množství příkazů specifických pro prohlížeč (např. `alert`) na minimu, abyste nad nimi nemuseli ztrácet čas, jestliže se plánujete zaměřit na jiné prostředí (např. Node.js). Na JavaScript v prohlížeči se zaměříme v [další části](/ui) tutoriálu.
66

7-
So first, let's see how we attach a script to a webpage. For server-side environments (like Node.js), you can execute the script with a command like `"node my.js"`.
7+
Nejprve se podíváme, jak vložit skript na webovou stránku. V prostředích na straně serveru (např. Node.js) můžete spustit skript příkazem, například `"node my.js"`.
88

99

10-
## The "script" tag
10+
## Značka „script
1111

12-
JavaScript programs can be inserted almost anywhere into an HTML document using the `<script>` tag.
12+
Programy v JavaScriptu můžeme vložit téměř kamkoli v HTML dokumentu pomocí značky `<script>`.
1313

14-
For instance:
14+
Příklad:
1515

1616
```html run height=100
1717
<!DOCTYPE HTML>
1818
<html>
1919

2020
<body>
2121

22-
<p>Before the script...</p>
22+
<p>Před skriptem...</p>
2323

2424
*!*
2525
<script>
26-
alert( 'Hello, world!' );
26+
alert( 'Ahoj, světe!' );
2727
</script>
2828
*/!*
2929

30-
<p>...After the script.</p>
30+
<p>...a za skriptem.</p>
3131

3232
</body>
3333

3434
</html>
3535
```
3636

3737
```online
38-
You can run the example by clicking the "Play" button in the right-top corner of the box above.
38+
Příklad si můžete přehrát kliknutím na tlačítko „Přehrát“ v pravém horním rohu ve výše uvedeném okně.
3939
```
4040

41-
The `<script>` tag contains JavaScript code which is automatically executed when the browser processes the tag.
41+
Značka `<script>` obsahuje kód v JavaScriptu, který se spustí automaticky, když prohlížeč začne tuto značku zpracovávat.
4242

4343

44-
## Modern markup
44+
## Moderní značení
4545

46-
The `<script>` tag has a few attributes that are rarely used nowadays but can still be found in old code:
46+
Značka `<script>` má některé atributy, které se v současnosti používají jen zřídka, ale stále je můžeme najít ve starším kódu:
4747

48-
The `type` attribute: <code>&lt;script <u>type</u>=...&gt;</code>
49-
: The old HTML standard, HTML4, required a script to have a `type`. Usually it was `type="text/javascript"`. It's not required anymore. Also, the modern HTML standard totally changed the meaning of this attribute. Now, it can be used for JavaScript modules. But that's an advanced topic, we'll talk about modules in another part of the tutorial.
48+
Atribut `type`: <code>&lt;script <u>type</u>=...&gt;</code>
49+
: Starý standard HTML, HTML4, vyžadoval, aby skript byl určitého typu (`type`). Obvykle to byl `type="text/javascript"`. To už dnes není nutné. Kromě toho moderní standard HTML zcela změnil význam tohoto atributu, který se dnes může používat pro moduly JavaScriptu. To je však pokročilejší záležitost. Na moduly se zaměříme v další části tohoto tutoriálu.
5050

51-
The `language` attribute: <code>&lt;script <u>language</u>=...&gt;</code>
52-
: This attribute was meant to show the language of the script. This attribute no longer makes sense because JavaScript is the default language. There is no need to use it.
51+
Atribut `language`: <code>&lt;script <u>language</u>=...&gt;</code>
52+
: Tento atribut měl oznamovat jazyk (language) skriptu. Protože výchozím jazykem je dnes JavaScript, nemá již tento atribut smysl a není třeba jej používat.
5353

54-
Comments before and after scripts.
55-
: In really ancient books and guides, you may find comments inside `<script>` tags, like this:
54+
Komentáře před a za skripty.
55+
: V zastaralých knihách a průvodcích můžete uvnitř značky `<script>` najít takovéto komentáře:
5656

5757
```html no-beautify
5858
<script type="text/javascript"><!--
5959
...
6060
//--></script>
6161
```
6262

63-
This trick isn't used in modern JavaScript. These comments hide JavaScript code from old browsers that didn't know how to process the `<script>` tag. Since browsers released in the last 15 years don't have this issue, this kind of comment can help you identify really old code.
63+
Tento trik se v moderním JavaScriptu již nepoužívá. Tyto komentáře znepřístupňovaly JavaScriptový kód starým prohlížečům, které neuměly zpracovat značku `<script>`. Protože každý prohlížeč vydaný v posledních 15 letech to umí, můžete podle tohoto komentáře poznat opravdu starý kód.
6464

6565

66-
## External scripts
66+
## Externí skripty
6767

68-
If we have a lot of JavaScript code, we can put it into a separate file.
68+
Máme-li větší množství kódu v JavaScriptu, můžeme jej uložit do samostatného souboru.
6969

70-
Script files are attached to HTML with the `src` attribute:
70+
Tyto soubory se přidávají do HTML pomocí atributu `src`:
7171

7272
```html
73-
<script src="/path/to/script.js"></script>
73+
<script src="/cesta/ke/skriptu.js"></script>
7474
```
7575

76-
Here, `/path/to/script.js` is an absolute path to the script from the site root. One can also provide a relative path from the current page. For instance, `src="script.js"`, just like `src="./script.js"`, would mean a file `"script.js"` in the current folder.
76+
Zde `/cesta/ke/skriptu.js` je absolutní cesta ke skriptu z kořenové složky webového sídla. Můžeme uvést i relativní cestu od aktuální stránky. Například `src="script.js"`, stejně jako `src="./script.js"`, by znamenalo soubor `"script.js"` v aktuální složce.
7777

78-
We can give a full URL as well. For instance:
78+
Můžeme poskytnout i úplné URL. Například:
7979

8080
```html
8181
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.js"></script>
8282
```
8383

84-
To attach several scripts, use multiple tags:
84+
Chceme-li připojit více skriptů, použijeme více značek:
8585

8686
```html
8787
<script src="/js/script1.js"></script>
@@ -90,43 +90,43 @@ To attach several scripts, use multiple tags:
9090
```
9191

9292
```smart
93-
As a rule, only the simplest scripts are put into HTML. More complex ones reside in separate files.
93+
Bývá pravidlem, že do HTML se ukládají jen ty nejjednodušší skripty. Složitější se umisťují do oddělených souborů.
9494
95-
The benefit of a separate file is that the browser will download it and store it in its [cache](https://en.wikipedia.org/wiki/Web_cache).
95+
Výhodou odděleného souboru je, že prohlížeč si jej stáhne a uloží do své [mezipaměti](https://en.wikipedia.org/wiki/Web_cache).
9696
97-
Other pages that reference the same script will take it from the cache instead of downloading it, so the file is actually downloaded only once.
97+
Jiné stránky, které se odkazují na stejný skript, si jej místo opětovného stažení nahrají z mezipaměti, takže se soubor ve skutečnosti stáhne pouze jednou.
9898
99-
That reduces traffic and makes pages faster.
99+
Tím se snižuje přenos dat a načítání stránek je tak rychlejší.
100100
```
101101

102-
````warn header="If `src` is set, the script content is ignored."
103-
A single `<script>` tag can't have both the `src` attribute and code inside.
102+
````warn header="Je-li nastaveno `src`, obsah značky se ignoruje."
103+
Jedna značka `<script>` nemůže obsahovat atribut `src` a kód současně.
104104

105-
This won't work:
105+
Tohle nebude fungovat:
106106

107107
```html
108-
<script *!*src*/!*="file.js">
109-
alert(1); // the content is ignored, because src is set
108+
<script *!*src*/!*="soubor.js">
109+
alert(1); // obsah je ignorován, protože je nastaveno src
110110
</script>
111111
```
112112

113-
We must choose either an external `<script src="…">` or a regular `<script>` with code.
113+
Musíme si vybrat mezi externím `<script src="…">` a vloženým `<script>` skriptem.
114114

115-
The example above can be split into two scripts to work:
115+
Výše uvedený příklad může fungovat, když jej rozdělíme do dvou skriptů:
116116

117117
```html
118-
<script src="file.js"></script>
118+
<script src="soubor.js"></script>
119119
<script>
120120
alert(1);
121121
</script>
122122
```
123123
````
124124
125-
## Summary
125+
## Shrnutí
126126
127-
- We can use a `<script>` tag to add JavaScript code to a page.
128-
- The `type` and `language` attributes are not required.
129-
- A script in an external file can be inserted with `<script src="path/to/script.js"></script>`.
127+
- JavaScriptový kód můžeme umístit na stránku pomocí značky `<script>`.
128+
- Atributy `type` a `language` nejsou vyžadovány.
129+
- Skript v externím souboru lze vložit pomocí `<script src="cesta/ke/skriptu.js"></script>`.
130130
131131
132-
There is much more to learn about browser scripts and their interaction with the webpage. But let's keep in mind that this part of the tutorial is devoted to the JavaScript language, so we shouldn't distract ourselves with browser-specific implementations of it. We'll be using the browser as a way to run JavaScript, which is very convenient for online reading, but only one of many.
132+
O skriptech v prohlížeči a jejich interakcí s webovou stránkou toho lze napsat mnohem více. Mějme však na paměti, že tato část tutoriálu je věnována pouze jazyku JavaScript, takže bychom se zde neměli zatěžovat specifiky jeho implementací v prohlížečích. Ke spouštění skriptů v JavaScriptu budeme používat prohlížeč, což je při online čtení velmi výhodné, ale je to jen jedna z mnoha možností.

0 commit comments

Comments
 (0)
Please sign in to comment.