-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
101 lines (73 loc) · 2.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!doctype html>
<html lang="en">
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous">
<head>
<meta charset="utf-8">
<title>Al-qur'an </title>
<style>
</style>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>
<a href="#" id="get-data"></a>
<div>
<div class="container text-center" >
<div class="row mt-3">
<div class="col-1 bg-warning text-light">
<div class="font-weight-bold" style="height: 50px;" > <P style="margin-top: 15px;">Nomor Surat</P></div>
<div id="nomor" class="p-3 mb-2 bg-secondary text-light" ></div>
</div>
<div class="col-4 bg-warning text-light" >
<div class="font-weight-bold" style="height: 50px;"> <p style="margin-top: 15px;"> Daftar Surah</p></div>
<div id="show-data" class="p-3 mb-2 bg-secondary text-light"></div>
</div>
<div class="col-7 overflow-auto bg-warning text-light" style="height: 800px;">
<div class="font-weight-bold" style="height: 50px;" > <P style="margin-top: 15px;"> Daftar Ayat </P></div>
<div id="ayat" class="p-3 mb-2 bg-secondary text-light"></div>
</div>
</div>
</div>
</div>
</body>
<script>
$(document).ready(() => {
const $showData = $('#show-data');
const $raw = $('pre');
// get json di endpoint
$.getJSON('https://api.alquran.cloud/v1/surah', (respon) => {
console.log(respon.code);
console.log(respon.status);
// mengatur ulang format respon dari json menjadi html
const head = '<tr><th></th></tr>';
const markup = respon.data
.map(item => `<tr><td class="surat" idayat="${item.number}" style="height:30px">
${item.name}
</td></tr>`)
.join('');
const nomor = respon.data
.map(item => `<tr><td class="surat" idayat="${item.number}" style="height:30px">
${item.number}
</td></tr>`)
.join('');
const list = $('<table />').html(head + markup);
// tampilkan di kolom ke dua
$('#show-data').html(list);
$('#nomor').html(nomor);
$('.surat').on('click', function (event) {
$(this).attr("idayat");
$.getJSON('https://api.alquran.cloud/v1/surah/' + $(this).attr("idayat"), (respon) => {
const ayat = respon.data.ayahs
.map(item => `<p>
(${item.numberInSurah}) ${item.text}
</p>`)
.join('');
$('#ayat').html(ayat);
});
});
});
});
</script>
</html>