You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 2-ui/2-events/01-introduction-browser-events/article.md
+30-30Lines changed: 30 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -283,70 +283,70 @@ Beberapa pemanggilan ke `addEventListener` mengijinkan untuk menambahkan beberap
283
283
</script>
284
284
```
285
285
286
-
As we can see in the example above, we can set handlers *both* using a DOM-property and`addEventListener`. But generally we use only one of these ways.
286
+
Seperti yang bisa kita lihat pada contoh di atas, kita bisa mengatur *kedua* pengendali menggunakan properti DOM dan`addEventListener`. Tapi pada umumnya kita hanya akan menggunakan salah satu.
287
287
288
-
````warn header="For some events, handlers only work with`addEventListener`"
289
-
There exist events that can't be assigned via a DOM-property. Only with`addEventListener`.
288
+
````warn header="Untuk beberapa peristiwa, pengendali bekerja hanya dengan`addEventListener`"
289
+
Ada beberapa peristiwa yang tidak dapat di atur menggunakan properti DOM. hanya dengan`addEventListener`.
290
290
291
-
For instance, the`DOMContentLoaded` event, that triggers when the document is loaded and DOM is built.
291
+
Contohnya, peristiwa`DOMContentLoaded`, yang akan terpicu pada saat dokumen telah berhasil di dimuat dan dibuat.
So`addEventListener`is more universal. Although, such events are an exception rather than the rule.
306
+
Jadi`addEventListener`lebih universal. Walaupun, aturan semacam itu merupakan sebuah pengecualian daripada aturan.
307
307
````
308
308
309
-
## Event object
309
+
## Objek peristiwa (Event object)
310
310
311
-
To properly handle an event we'd want to know more about what's happened. Not just a "click" or a "keydown", but what were the pointer coordinates? Which key was pressed? And so on.
311
+
Untuk menangani peristiwa secara benar sebuah peristiwa kita mau tahu lebih tentang apa yang terjadi. Tidak hanya sebuah "klik" atau sebuah "penekanan tombol", tapi apa koordinat pointer? tombol mana yang di tekan? dan seterusnya.
312
312
313
-
When an event happens, the browser creates an *event object*, puts details into it and passes it as an argument to the handler.
313
+
Pada saat sebuah peristiwa terjadi, peramban akan membuat *objek peristiwa*, memasukan detail kedalamnya dan meneruskan peristiwa tersebut ke pengendali sebagai sebuah argumen.
314
314
315
-
Here's an example of getting pointer coordinates from the event object:
315
+
Ini merupakan contoh cara untuk mendapat koordinat pointer dari objek peristiwa:
316
316
317
317
```html run
318
-
<input type="button" value="Click me" id="elem">
318
+
<input type="button" value="Klik saya" id="elem">
319
319
320
320
<script>
321
-
elem.onclick = function(*!*event*/!*) {
322
-
// show event type, element and coordinates of the click
: Element that handled the event. That's exactly the same as `this`, unless the handler is an arrow function, or its `this` is bound to something else, then we can get the element from `event.currentTarget`.
334
+
`peristiwa.currentTarget`
335
+
: elemen yang ditangani oleh peristiwa. Sama persis dengan `this`, kecuali jika pengendali merupakan fungsi anak panah (arrow function), atau `this` sudah di atur untuk hal lain, maka kita dapat menggunakan `peristiwa.currentTarget` untuk mendapati elemen.
336
336
337
-
`event.clientX / event.clientY`
338
-
: Window-relative coordinates of the cursor, for pointer events.
337
+
`peristiwa.clientX / peristiwa.clientY`
338
+
: koordinat kursor relatif pada jendela (window), untuk peristwa pointer.
339
339
340
-
There are more properties. Many of them depend on the event type: keyboard events have one set of properties, pointer events - another one, we'll study them later when we come to different events in details.
340
+
Masih banyak lagi properti. Banyak yang tergantung pada tipe peristiwa: peristiwa papan ketik memilik satu set properti, peristiwa pointer - memiliki set yang berbeda, kita nanti akan mempelajari mereka pada saat kita mendapati peristiwa lainnya secara detail.
341
341
342
-
````smart header="The event object is also available in HTML handlers"
343
-
If we assign a handler in HTML, we can also use the `event` object, like this:
342
+
````smart header="Objek peristiwa juga ada pada pengendali HTML"
343
+
Jika kita mengatur pengendali pada HTML, kita bisa juga menggunakan objek peristiwa, seperti ini:
That's possible because when the browser reads the attribute, it creates a handler like this: `function(event) {alert(event.type) }`. That is: its first argument is called `"event"`, and the body is taken from the attribute.
349
+
Ini terjadi karena pada saat peramban membaca atribut, itu membuat sebuah pengendali seperti ini: `function(event) {alert(event.type) }`. yaitu: argumen pertamanya disebut dengan `"event"`, dan tubuhnya di ambil dari atribut.
0 commit comments