Skip to content

Commit e053b94

Browse files
authored
Merge pull request #245 from EmptyWork/master
Browser default actions
2 parents 47974b2 + 03ec5d9 commit e053b94

File tree

8 files changed

+124
-125
lines changed

8 files changed

+124
-125
lines changed

2-ui/2-events/04-default-browser-action/1-why-return-false-fails/solution.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
When the browser reads the `on*` attribute like `onclick`, it creates the handler from its content.
1+
Pada saat _browser_ membaca atribut `on*` seperti `onclick`, _browser_ akan membuat sebuah penangan (_handler_) dari kontennya.
22

3-
For `onclick="handler()"` the function will be:
3+
Untuk `onclick"handler()"` fungsinya akan menjadi:
44

55
```js
66
function(event) {
7-
handler() // the content of onclick
7+
handler() // konten dari onclick
88
}
99
```
1010

11-
Now we can see that the value returned by `handler()` is not used and does not affect the result.
11+
Sekarang kita bisa melihat bahwa nilai yang dikembalikan oleh `handler()` tidak digunakan dan tidak mempengaruhi hasilnya.
1212

13-
The fix is simple:
13+
Cara memperbaikinnya mudah:
1414

1515
```html run
1616
<script>
@@ -23,7 +23,7 @@ The fix is simple:
2323
<a href="https://w3.org" onclick="*!*return handler()*/!*">w3.org</a>
2424
```
2525

26-
Also we can use `event.preventDefault()`, like this:
26+
Kita juga bisa menggunakan `event.preventDefault()`, seperti ini:
2727

2828
```html run
2929
<script>

2-ui/2-events/04-default-browser-action/1-why-return-false-fails/task.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 3
22

33
---
44

5-
# Why "return false" doesn't work?
5+
# Mengapa "return false" tidak berfungsi?
66

7-
Why in the code below `return false` doesn't work at all?
7+
Kenapa pada kode dibawah `return false` tidak berfungsi sama sekali?
88

99
```html autorun run
1010
<script>
@@ -14,9 +14,9 @@ Why in the code below `return false` doesn't work at all?
1414
}
1515
</script>
1616

17-
<a href="https://w3.org" onclick="handler()">the browser will go to w3.org</a>
17+
<a href="https://w3.org" onclick="handler()">browser akan membuka w3.org</a>
1818
```
1919

20-
The browser follows the URL on click, but we don't want it.
20+
_browser_ akan mengikuti URL yang di klik, tapi kita tidak mau hal itu terjadi.
2121

22-
How to fix?
22+
Bagaimana cara memperbaikinya?
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
That's a great use of the event delegation pattern.
1+
Itu merupakan salah satu cara yang bagus dalam pemanfaatan pola delegasi peristiwa.
22

3-
In real life instead of asking we can send a "logging" request to the server that saves the information about where the visitor left. Or we can load the content and show it right in the page (if allowable).
3+
Pada kehidupan nyata kita bisa mengirim permintaan "logging" ke server yang menyimpan informasi tentang dari mana pengujung meninggalkan website daripada menanyakannya secara langsung. Atau kita bisa memuat konten dan menunjukannya tepat pada halaman (jika diizinkan).
44

5-
All we need is to catch the `contents.onclick` and use `confirm` to ask the user. A good idea would be to use `link.getAttribute('href')` instead of `link.href` for the URL. See the solution for details.
5+
Yang kita butuhkan hanyalah menangkap `contents.onclick` dan menggunakan `confim` untuk menanyakan pengguna. Sebuah ide bagus adalah dengan menggunakan `link.getAttribute('href')` dari pada menggunakan `link.href` untuk URL. Lihat solusinya untuk rincian.

2-ui/2-events/04-default-browser-action/2-catch-link-navigation/solution.view/index.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
<body>
1515

1616
<fieldset id="contents">
17-
<legend>#contents</legend>
17+
<legend>#kontent</legend>
1818
<p>
19-
How about to read <a href="https://wikipedia.org">Wikipedia</a> or visit <a href="https://w3.org"><i>W3.org</i></a> and learn about modern standards?
19+
Bagaimana jika membaca di <a href="https://wikipedia.org">Wikipedia</a> atau kunjungi <a href="https://w3.org"><i>W3.org</i></a> dan belajar tentang standar terbaru?
2020
</p>
2121
</fieldset>
2222

2323
<script>
2424
contents.onclick = function(event) {
2525

2626
function handleLink(href) {
27-
let isLeaving = confirm(`Leave for ${href}?`);
27+
let isLeaving = confirm(`Pergi ke ${href}?`);
2828
if (!isLeaving) return false;
2929
}
3030

2-ui/2-events/04-default-browser-action/2-catch-link-navigation/source.view/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
<body>
1515

1616
<fieldset id="contents">
17-
<legend>#contents</legend>
17+
<legend>#kontent</legend>
1818
<p>
19-
How about to read <a href="https://wikipedia.org">Wikipedia</a> or visit <a href="https://w3.org"><i>W3.org</i></a> and learn about modern standards?
19+
Bagaimana jika membaca di <a href="https://wikipedia.org">Wikipedia</a> atau kunjungi <a href="https://w3.org"><i>W3.org</i></a> dan belajar tentang standar terbaru?
2020
</p>
2121
</fieldset>
2222

Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
importance: 5
22

33
---
4+
# Tangkap link pada elemen
45

5-
# Catch links in the element
6+
Buat semua link yang ada didalam elemen dengan `id="contents"` akan menanyakan kepada pengguna jika mereka mau meninggalkan website. Dan jika mereka tidak mau maka halaman tidak akan berpindah.
67

7-
Make all links inside the element with `id="contents"` ask the user if they really want to leave. And if they don't then don't follow.
8-
9-
Like this:
8+
Seperti ini:
109

1110
[iframe height=100 border=1 src="solution"]
1211

13-
Details:
12+
Rincian:
1413

15-
- HTML inside the element may be loaded or regenerated dynamically at any time, so we can't find all links and put handlers on them. Use event delegation.
16-
- The content may have nested tags. Inside links too, like `<a href=".."><i>...</i></a>`.
14+
- HTML didalam elemen bisa di muat dan di buat kembali secara dinamis secara acak, jadi kita tidak bisa menemukan semua link dan memberikan penangan (_handler_). Gunakan delegasi peristiwa.
15+
- Kontent bisa saja merupakan tag bersarang. Di dalam link juga, seperti `<a href=".."><i>...</i></a>`.

0 commit comments

Comments
 (0)