Skip to content

Commit 067d76a

Browse files
authored
Merge pull request #236 from EmptyWork/master
Introduction to browser events
2 parents 0a7a0ad + d24f862 commit 067d76a

File tree

16 files changed

+184
-184
lines changed

16 files changed

+184
-184
lines changed

2-ui/2-events/01-introduction-browser-events/03-which-handlers-run/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Jawabannya: `1` dan `2`.
22

3-
Pengendali pertama dijalankan, karena tidak di hapuskan oleh `removeEventListener`. Untuk menghapuskan pengendali kita harus meneruskan secara tepat fungsi yang telah di atur. Dan pada kode sebuah fungsi baru di teruskan, terlihat sama, tapi berbeda fungsi.
3+
penangan pertama dijalankan, karena tidak di hapuskan oleh `removeEventListener`. Untuk menghapuskan penangan kita harus meneruskan secara tepat fungsi yang telah di atur. Dan pada kode sebuah fungsi baru di teruskan, terlihat sama, tapi berbeda fungsi.
44

55
Untuk menghapuskan objek fungsi, kita harus menyimpan refensi ke fungsi tersebut, seperti ini:
66

@@ -13,4 +13,4 @@ button.addEventListener("click", handler);
1313
button.removeEventListener("click", handler);
1414
```
1515

16-
Pengendali `button.onclick` bekerja secara sendiri dan sebagai tambahan untuk `addEvenetListener`.
16+
penangan `button.onclick` bekerja secara sendiri dan sebagai tambahan untuk `addEvenetListener`.

2-ui/2-events/01-introduction-browser-events/03-which-handlers-run/task.md

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

33
---
44

5-
# Pengendali mana yang dijalankan?
5+
# Penangan mana yang dijalankan?
66

77
Ada sebuah tombol pada variable. Tidak ada pengedali di tombol tersebut.
88

9-
Manakah pengendali yang dijalankan pada saat klik pada kode berikut ini? Manakah `alert` yang akan ditunjukan?
9+
Manakah penangan yang dijalankan pada saat klik pada kode berikut ini? Manakah `alert` yang akan ditunjukan?
1010

1111
```js no-beautify
1212
button.addEventListener("click", () => alert("1"));
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

2-
First we need to choose a method of positioning the ball.
2+
Pertama kita perlu memilih metode untuk memposisikan bola.
33

4-
We can't use `position:fixed` for it, because scrolling the page would move the ball from the field.
4+
Kita tidak dapat menggunakan `position:fixed` untuk itu, karena pada saat halaman digulir bola akan berpindah dari lapangan.
55

6-
So we should use `position:absolute` and, to make the positioning really solid, make `field` itself positioned.
6+
Jadi kita sebaiknya menggunakan `position:absolute` dan, untuk membuat posisinya benar-benar tepat, buat lapangan(_`field`_) itu sendiri diposisikan.
77

8-
Then the ball will be positioned relatively to the field:
8+
Kemudian bola akan diposisikan relatif terhadap lapangan(_`field`_):
99

1010
```css
1111
#field {
@@ -16,36 +16,36 @@ Then the ball will be positioned relatively to the field:
1616

1717
#ball {
1818
position: absolute;
19-
left: 0; /* relative to the closest positioned ancestor (field) */
19+
left: 0; /* relatif ke posisi terdekat blok atas (lapangan) */
2020
top: 0;
21-
transition: 1s all; /* CSS animation for left/top makes the ball fly */
21+
transition: 1s all; /* Animasi CSS untuk left/top untuk membuat bolanya terbang */
2222
}
2323
```
2424

25-
Next we need to assign the correct `ball.style.left/top`. They contain field-relative coordinates now.
25+
Selanjutnya kita harus mengatur dengan benar `ball.style.left/top`. Mereka memiliki koordinat relatif ke lapangan(_`field`_) sekarang.
2626

27-
Here's the picture:
27+
Berikut ini gambarnya:
2828

2929
![](move-ball-coords.svg)
3030

31-
We have `event.clientX/clientY` -- window-relative coordinates of the click.
31+
Kita memiliki `event.clientX/clientY` -- koordinat relatif jendela (_window_) dari klik.
3232

33-
To get field-relative `left` coordinate of the click, we can substract the field left edge and the border width:
33+
Untuk mendapatkan koordinat kiri relatif terhadap lapangan(_`field`_), kita kurangkan dengan nilai dari ujung dan pembatas kiri lapangan:
3434

3535
```js
3636
let left = event.clientX - fieldCoords.left - field.clientLeft;
3737
```
3838

39-
Normally, `ball.style.left` means the "left edge of the element" (the ball). So if we assign that `left`, then the ball edge, not center, would be under the mouse cursor.
39+
Biasanya, `ball.style.left` artinya "ujung kiri dari elemen" (bola). Jadi kita mengatur nilai `left`, kemudian ujung bola, bukan tengah, akan berada tepat dibawah kursor mouse.
4040

41-
We need to move the ball half-width left and half-height up to make it center.
41+
Kita perlu memindahkan bola setengah lebar kiri dan setengah tinggi atas untuk membuatnya di tengah.
4242

43-
So the final `left` would be:
43+
Jadi nilai terakhir `left` akan menjadi:
4444

4545
```js
4646
let left = event.clientX - fieldCoords.left - field.clientLeft - ball.offsetWidth/2;
4747
```
4848

49-
The vertical coordinate is calculated using the same logic.
49+
Koordinat vertikal di ukur dengan menggunakan logika yang sama.
5050

51-
Please note that the ball width/height must be known at the time we access `ball.offsetWidth`. Should be specified in HTML or CSS.
51+
Harap dicatat bahwa lebar/tinggi bola harus di ketahui pada saat kita mengakses `ball.offsetWidth`. Sebaiknya di atur pada HTML atau CSS.

2-ui/2-events/01-introduction-browser-events/05-sliding-menu/solution.md

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,47 @@
11

22
# HTML/CSS
3-
First let's create HTML/CSS.
3+
Pertama buat HTML/CSS.
44

5-
A menu is a standalone graphical component on the page, so it's better to put it into a single DOM element.
5+
Sebuah menu adalah komponen tersendiri pada halaman, jadi lebih baik untuk menaruhnya kedalam satu elemen DOM.
66

7-
A list of menu items can be laid out as a list `ul/li`.
7+
Sebuah daftar dari item menu bisa dapat diatur kedalam daftar menggunakan `ul/li`.
88

9-
Here's the example structure:
9+
Ini contoh strukturnya:
1010

1111
```html
1212
<div class="menu">
13-
<span class="title">Sweeties (click me)!</span>
13+
<span class="title">Manis-Manis (Tekan saya)!</span>
1414
<ul>
15-
<li>Cake</li>
16-
<li>Donut</li>
17-
<li>Honey</li>
15+
<li>Kue</li>
16+
<li>Donat</li>
17+
<li>Madu</li>
1818
</ul>
1919
</div>
2020
```
2121

22-
We use `<span>` for the title, because `<div>` has an implicit `display:block` on it, and it will occupy 100% of the horizontal width.
22+
Kita dapat menggunakan `<span>` untuk judul, karena `<div>` memiliki `display:block`, dan akan memenuhi 100% horisontal lebar elemen.
2323

24-
Like this:
24+
Seperti ini:
2525

2626
```html autorun height=50
27-
<div style="border: solid red 1px" onclick="alert(1)">Sweeties (click me)!</div>
27+
<div style="border: solid red 1px" onclick="alert(1)">Manis-Manis (Tekan saya)!</div>
2828
```
2929

30-
So if we set `onclick` on it, then it will catch clicks to the right of the text.
30+
Jadi jika kita mengatur `onclick` pada judul, maka itu akan menangkap klik diselah kanan teks.
3131

32-
As `<span>` has an implicit `display: inline`, it occupies exactly enough place to fit all the text:
32+
Sedangkan `<span>` memiliki `display:inline`, dan akan memenuhi ruang yang cukup sesuai dengan teks:
3333

3434
```html autorun height=50
35-
<span style="border: solid red 1px" onclick="alert(1)">Sweeties (click me)!</span>
35+
<span style="border: solid red 1px" onclick="alert(1)">Manis-Manis (Tekan saya)!</span>
3636
```
3737

38-
# Toggling the menu
38+
# Membuka dan menutup menu
3939

40-
Toggling the menu should change the arrow and show/hide the menu list.
40+
Membuka dan menutup menu seharusnya menganti posisi anak panah dan menunjukan atau menyembunyikan daftar menu.
4141

42-
All these changes are perfectly handled by CSS. In JavaScript we should label the current state of the menu by adding/removing the class `.open`.
43-
44-
Without it, the menu will be closed:
42+
Semua pergantian ini sangat sempurna untuk di tanggani oleh CSS. Pada Javascript kita harus memberi label pada kondisi menu saat ini dengan menambahkan/menghapuskan kelas(_class_) `.open`.
4543

44+
Tanpanya, menu akan tetap tertutup:
4645
```css
4746
.menu ul {
4847
margin: 0;
@@ -58,7 +57,7 @@ Without it, the menu will be closed:
5857
}
5958
```
6059

61-
...And with `.open` the arrow changes and the list shows up:
60+
...Dan dengan `.open` anak panah akan berubah dan daftar akan kelihatan:
6261

6362
```css
6463
.menu.open .title::before {

2-ui/2-events/01-introduction-browser-events/05-sliding-menu/solution.view/index.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
color: green;
2323
}
2424

25-
.menu.open .title::before {
25+
.menu.buka .title::before {
2626
content: '▼ ';
2727
}
2828

29-
.menu.open ul {
29+
.menu.buka ul {
3030
display: block;
3131
}
3232
</style>
@@ -35,11 +35,11 @@
3535
<body>
3636

3737
<div id="sweeties" class="menu">
38-
<span class="title">Sweeties (click me)!</span>
38+
<span class="title">Manis-Manis (Klik Saya)!</span>
3939
<ul>
40-
<li>Cake</li>
41-
<li>Donut</li>
42-
<li>Honey</li>
40+
<li>Kue</li>
41+
<li>Donat</li>
42+
<li>Madu</li>
4343
</ul>
4444

4545
</div>
@@ -49,7 +49,7 @@
4949
let titleElem = menuElem.querySelector('.title');
5050

5151
titleElem.onclick = function() {
52-
menuElem.classList.toggle('open');
52+
menuElem.classList.toggle('buka');
5353
};
5454
</script>
5555

2-ui/2-events/01-introduction-browser-events/05-sliding-menu/source.view/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
</head>
66
<body>
77

8-
▶ ▼ Sweeties (click me)!
8+
▶ ▼ Manis-Manis (Klik Saya)!
99
<ul>
10-
<li>Cake</li>
11-
<li>Donut</li>
12-
<li>Honey</li>
10+
<li>Kue</li>
11+
<li>Donat</li>
12+
<li>Madu</li>
1313
</ul>
1414

1515
</body>

2-ui/2-events/01-introduction-browser-events/05-sliding-menu/task.md

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

33
---
44

5-
# Create a sliding menu
5+
# Buat sebuah menu geser
66

7-
Create a menu that opens/collapses on click:
7+
Buat sebuah menu yang terbuka/tertutup pada saat ditekan:
88

99
[iframe border=1 height=100 src="solution"]
1010

11-
P.S. HTML/CSS of the source document is to be modified.
11+
Tambahan: HTML/CSS dari dokumen harus dimodifikasi.

2-ui/2-events/01-introduction-browser-events/06-hide-message/solution.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11

2-
To add the button we can use either `position:absolute` (and make the pane `position:relative`) or `float:right`. The `float:right` has the benefit that the button never overlaps the text, but `position:absolute` gives more freedom. So the choice is yours.
2+
Untuk Menambahkan tombol kita bisa menggunakan `position:absolute` (dan membuat pane `position:relative`) atau `float:right`. `float:right` memiliki keuntung dimana tombol tidak akan perna tumpang tindih dengan teks, tetapi `position:absolute` memberikan lebih banyak kebebasan. Jadi pilihannya pada kamu.
33

4-
Then for each pane the code can be like:
4+
Kemudian pada setiap `pane` kodenya akan seperti ini:
55
```js
66
pane.insertAdjacentHTML("afterbegin", '<button class="remove-button">[x]</button>');
77
```
8-
9-
Then the `<button>` becomes `pane.firstChild`, so we can add a handler to it like this:
8+
Kemudian `<button>` menjadi `pane.firstChild`, jadi kita tambahkan sebuah penangan seperti ini:
109

1110
```js
1211
pane.firstChild.onclick = () => pane.remove();

2-ui/2-events/01-introduction-browser-events/06-hide-message/solution.view/index.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010

1111
<div>
1212
<div class="pane">
13-
<h3>Horse</h3>
14-
<p>The horse is one of two extant subspecies of Equus ferus. It is an odd-toed ungulate mammal belonging to the taxonomic family Equidae. The horse has evolved over the past 45 to 55 million years from a small multi-toed creature, Eohippus, into the large, single-toed animal of today.</p>
13+
<h3>Kuda</h3>
14+
<p>Kuda adalah salah satu dari dua subspesies Equus ferus yang masih ada. Ini adalah mamalia berkuku aneh milik keluarga taksonomi Equidae. Kuda telah berevolusi selama 45 hingga 55 juta tahun terakhir dari makhluk kecil berjari banyak, Eohippus, menjadi hewan besar berjari satu saat ini.</p>
1515
</div>
1616
<div class="pane">
17-
<h3>Donkey</h3>
18-
<p>The donkey or ass (Equus africanus asinus) is a domesticated member of the horse family, Equidae. The wild ancestor of the donkey is the African wild ass, E. africanus. The donkey has been used as a working animal for at least 5000 years.</p>
17+
<h3>Keledai</h3>
18+
<p>Keledai (Equus africanus asinus) adalah anggota keluarga kuda yang dijinakkan, Equidae. Nenek moyang keledai liar adalah keledai liar Afrika, E. africanus. Keledai telah digunakan sebagai hewan pekerja setidaknya selama 5000 tahun.</p>
1919
</div>
2020
<div class="pane">
21-
<h3>Cat</h3>
22-
<p>The domestic cat (Latin: Felis catus) is a small, typically furry, carnivorous mammal. They are often called house cats when kept as indoor pets or simply cats when there is no need to distinguish them from other felids and felines. Cats are often valued by humans for companionship and for their ability to hunt vermin.
21+
<h3>Kucing</h3>
22+
<p>Kucing domestik (bahasa Latin: Felis catus) adalah mamalia karnivora kecil yang biasanya berbulu. Mereka sering disebut kucing rumah ketika dipelihara sebagai hewan peliharaan dalam ruangan atau hanya kucing ketika tidak perlu membedakan mereka dari felids dan kucing lainnya. Kucing sering dihargai oleh manusia karena persahabatan dan kemampuan mereka untuk berburu hama.
2323
</p>
2424
</div>
2525
</div>
@@ -30,7 +30,7 @@ <h3>Cat</h3>
3030

3131
for(let pane of panes) {
3232
pane.insertAdjacentHTML("afterbegin", '<button class="remove-button">[x]</button>');
33-
// button becomes the first child of pane
33+
// Tombol menjadi anak pertama dari `pane`
3434
pane.firstChild.onclick = () => pane.remove();
3535
}
3636
</script>

2-ui/2-events/01-introduction-browser-events/06-hide-message/source.view/index.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88

99
<body>
1010

11-
The button code (may need to adjust CSS):
11+
Kode tombol (Kamu bisa mengubahnya menggunakan CSS):
1212
<button class="remove-button">[x]</button>
1313

1414
<div>
1515
<div class="pane">
16-
<h3>Horse</h3>
17-
<p>The horse is one of two extant subspecies of Equus ferus. It is an odd-toed ungulate mammal belonging to the taxonomic family Equidae. The horse has evolved over the past 45 to 55 million years from a small multi-toed creature, Eohippus, into the large, single-toed animal of today.</p>
16+
<h3>Kuda</h3>
17+
<p>Kuda adalah salah satu dari dua subspesies Equus ferus yang masih ada. Ini adalah mamalia berkuku aneh milik keluarga taksonomi Equidae. Kuda telah berevolusi selama 45 hingga 55 juta tahun terakhir dari makhluk kecil berjari banyak, Eohippus, menjadi hewan besar berjari satu saat ini.</p>
1818
</div>
1919
<div class="pane">
20-
<h3>Donkey</h3>
21-
<p>The donkey or ass (Equus africanus asinus) is a domesticated member of the horse family, Equidae. The wild ancestor of the donkey is the African wild ass, E. africanus. The donkey has been used as a working animal for at least 5000 years.</p>
20+
<h3>Keledai</h3>
21+
<p>Keledai (Equus africanus asinus) adalah anggota keluarga kuda yang dijinakkan, Equidae. Nenek moyang keledai liar adalah keledai liar Afrika, E. africanus. Keledai telah digunakan sebagai hewan pekerja setidaknya selama 5000 tahun.</p>
2222
</div>
2323
<div class="pane">
24-
<h3>Cat</h3>
25-
<p>The domestic cat (Latin: Felis catus) is a small, typically furry, carnivorous mammal. They are often called house cats when kept as indoor pets or simply cats when there is no need to distinguish them from other felids and felines. Cats are often valued by humans for companionship and for their ability to hunt vermin.
24+
<h3>Kucing</h3>
25+
<p>Kucing domestik (bahasa Latin: Felis catus) adalah mamalia karnivora kecil yang biasanya berbulu. Mereka sering disebut kucing rumah ketika dipelihara sebagai hewan peliharaan dalam ruangan atau hanya kucing ketika tidak perlu membedakan mereka dari felids dan kucing lainnya. Kucing sering dihargai oleh manusia karena persahabatan dan kemampuan mereka untuk berburu hama.
2626
</p>
2727
</div>
2828
</div>

0 commit comments

Comments
 (0)