Skip to content
6 changes: 3 additions & 3 deletions 2-ui/4-forms-controls/2-focus-blur/3-editable-div/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ importance: 5

# Editable div

Create a `<div>` that turns into `<textarea>` when clicked.
Buat sebuah `<div>` yang berubah menjadi`<textarea>` ketika diklik.

The textarea allows to edit the HTML in the `<div>`.
Textarea memungkinkan untuk mengedit HTML pada `<div>`.

When the user presses `key:Enter` or it loses focus, the `<textarea>` turns back into `<div>`, and its content becomes HTML in `<div>`.
Ketika user menekan `key:Enter` atau hilang fokus, maka `<textarea>` berubah kembali menjadi `<div>`, dan isinya menjadi HTML di dalam `<div>`.

[demo src="solution"]
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

1. On click -- replace `innerHTML` of the cell by `<textarea>` with same sizes and no border. Can use JavaScript or CSS to set the right size.
2. Set `textarea.value` to `td.innerHTML`.
3. Focus on the textarea.
4. Show buttons OK/CANCEL under the cell, handle clicks on them.
1. Saat diklik -- ganti `innerHTML` dari sel `<textarea>` dengan ukuran yang sama dan tanpa border. Bisa menggunakan JavaScript atau CSS untuk mengatur ukuran yang sesuai.
2. Ubah `textarea.value` ke `td.innerHTML`.
3. Fokus pada textarea.
4. Tampilkan tombol OK/CANCEL dibawah sel, tangani klik pada mereka.
12 changes: 6 additions & 6 deletions 2-ui/4-forms-controls/2-focus-blur/4-edit-td-click/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ importance: 5

# Edit TD on click

Make table cells editable on click.
Buat sel tabel yang dapat diedit saat diklik.

- On click -- the cell should became "editable" (textarea appears inside), we can change HTML. There should be no resize, all geometry should remain the same.
- Buttons OK and CANCEL appear below the cell to finish/cancel the editing.
- Only one cell may be editable at a moment. While a `<td>` is in "edit mode", clicks on other cells are ignored.
- The table may have many cells. Use event delegation.
- Saat diklik -- sel akan menjadi "editable" (textarea muncul dalam), kita bisa mengubah HTML. Tidak boleh mengubah ukurannya, semua geometri harus tetap sama..
- Tombol OK and CANCEL muncul di bawah sel untuk menyelesaikan atau membatalkan proses perubahan.
- Hanya satu sel yang dapat diedit setiap saatya. Sementara `<td>` dalam "edit mode", klik pada sel lain akan diabaikan.
- Tabel mungkin memilki banyak sel. Gunakan event _delegation_.

The demo:
Demo:

[iframe src="solution" height=400]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

We can use `mouse.onclick` to handle the click and make the mouse "moveable" with `position:fixed`, then `mouse.onkeydown` to handle arrow keys.
Kita bisa gunakan `mouse.onclick` untuk menangani klik dan membuat mouse "moveable/bergerak" dengan `position:fixed`, kemudian `mouse.onkeydown` untuk yang menangani tombol panah.

The only pitfall is that `keydown` only triggers on elements with focus. So we need to add `tabindex` to the element. As we're forbidden to change HTML, we can use `mouse.tabIndex` property for that.
Satu-satunya jebakan ialah `keydown` hanya memicu pada elemen dengan fokus. Jadi kita perlu untuk menambahkan `tabindex` pada elemen. Karena kita dilarang mengubah HTML, kita bisa gunakan properti `mouse.tabIndex` untuk itu.

P.S. We also can replace `mouse.onclick` with `mouse.onfocus`.
P.S. Kita juga bisa ganti `mouse.onclick` dengan `mouse.onfocus`.
6 changes: 3 additions & 3 deletions 2-ui/4-forms-controls/2-focus-blur/5-keyboard-mouse/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ importance: 4

# Keyboard-driven mouse

Focus on the mouse. Then use arrow keys to move it:
Fokus pada mouse. Lalu gunakan tombol arah untuk menggerakkannya:

[demo src="solution"]

P.S. Don't put event handlers anywhere except the `#mouse` element.
P.P.S. Don't modify HTML/CSS, the approach should be generic and work with any element.
P.S. Jangan letakkan event handler dimanapun kecuali pada elemen `#mouse`.
P.P.S. Jangan modifikasi HTML/CSS, pendekatannya harus umum dan bekerja dengan elemen manapun.
Loading