-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
337 lines (319 loc) · 15.8 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Al-Qur'an Web</title>
<!-- <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests"> -->
<link
href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css"
rel="stylesheet">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"
crossorigin="anonymous" referrerpolicy="no-referrer" />
<style>
@font-face {
font-family: 'Uthmani';
src: url('https://fonts.qurancomplex.gov.sa/wp-content/uploads/2021/02/UthmanicHafs1Ver09.otf') format('opentype');
font-weight: normal;
font-style: normal;
}
.modal {
display: none;
position: fixed;
z-index: 50;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.4);
}
.modal-content {
background-color: white;
margin: 10% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
.justify-text {
text-align: justify;
}
.text-right {
text-align: right;
}
.ayat-number {
font-family: 'Scheherazade New', serif;
font-size: 1.5em;
}
.ayat-arab {
font-family: 'Uthmani', serif;
font-size: 1.5em;
line-height: 2em;
}
</style>
</head>
<body class="bg-gray-100">
<div class="container mx-auto p-4">
<h1 class="text-2xl font-bold text-center mb-4">Al-Qur'an Web</h1>
<div class="flex justify-center items-center mb-4 space-x-4">
<div class="relative">
<select id="juzSelect"
class="p-2 border border-gray-300 rounded-md">
<option value selected>Pilih Juz</option>
</select>
<select id="surahSelect"
class="p-2 border border-gray-300 rounded-md">
<option value selected>Pilih Surah</option>
</select>
<select id="ayatSelect"
class="p-2 border border-gray-300 rounded-md">
<option value selected>Pilih Ayat</option>
</select>
<button id="goToAyat"
class="p-2 bg-blue-500 text-white rounded-md ml-2"><i
class="fas fa-arrow-right"></i></button>
</div>
<div class="relative w-2/3">
<input type="text" id="searchInput"
class="w-full p-2 border border-gray-300 rounded-md pl-10"
placeholder="Cari Surah atau Ayat...">
<i
class="fas fa-search absolute left-3 top-3 text-gray-400"></i>
</div>
</div>
<ul class="surah-list space-y-2" id="surahList"></ul>
</div>
<div id="surahModal" class="modal">
<div class="modal-content rounded-lg shadow-lg">
<span class="close" id="closeModal">×</span>
<h2 id="surahName" class="text-xl font-bold mb-2"></h2>
<p id="surahInfo" class="mb-4 justify-text"></p>
<h3 class="text-lg font-semibold mb-2">Ayat</h3>
<div id="ayatList" class="mb-4"></div>
<h3 class="text-lg font-semibold mb-2">Tafsir</h3>
<div id="tafsirList"></div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function () {
const surahList = document.getElementById('surahList');
const surahModal = document.getElementById('surahModal');
const closeModal = document.getElementById('closeModal');
const surahName = document.getElementById('surahName');
const surahInfo = document.getElementById('surahInfo');
const ayatList = document.getElementById('ayatList');
const tafsirList = document.getElementById('tafsirList');
const searchInput = document.getElementById('searchInput');
const surahSelect = document.getElementById('surahSelect');
const ayatSelect = document.getElementById('ayatSelect');
const juzSelect = document.getElementById('juzSelect');
const goToAyat = document.getElementById('goToAyat');
let allSurahs = [];
fetch('https://equran.id/api/v2/surat')
.then(response => response.json())
.then(data => {
allSurahs = data.data;
displaySurahs(allSurahs);
populateSurahDropdown(allSurahs);
// Simpan data ke local storage
localStorage.setItem('daftarSurah', JSON.stringify(data));
console.log('Data tersimpan di local storage:', data);
})
.catch(error => console.error('Error fetching surah list:', error));
searchInput.addEventListener('input', () => {
const query = searchInput.value.toLowerCase();
const filteredSurahs = allSurahs.filter(surah =>
surah.namaLatin.toLowerCase().includes(query) ||
surah.nama.toLowerCase().includes(query) ||
surah.nomor.toString().includes(query)
);
displaySurahs(filteredSurahs);
});
surahSelect.addEventListener('change', () => {
const surahNumber = surahSelect.value;
if (surahNumber) {
fetch(`https://equran.id/api/v2/surat/${surahNumber}`)
.then(response => response.json())
.then(data => {
const surah = data.data;
populateAyatDropdown(surah.jumlahAyat);
})
.catch(error => console.error('Error fetching surah detail:', error));
} else {
ayatSelect.innerHTML = '<option value="" selected>Pilih Ayat</option>';
}
});
juzSelect.addEventListener('change', () => {
const juzNumber = juzSelect.value;
if (juzNumber) {
fetch(`https://equran.id/api/v2/juz/${juzNumber}`)
.then(response => response.json())
.then(data => {
const surahIds = data.data.map(item => item.surah_id);
const surahsInJuz = allSurahs.filter(surah => surahIds.includes(surah.nomor));
populateSurahDropdown(surahsInJuz);
})
.catch(error => console.error('Error fetching juz detail:', error));
} else {
populateSurahDropdown(allSurahs);
}
});
goToAyat.addEventListener('click', () => {
const surahNumber = surahSelect.value;
const ayatNumber = ayatSelect.value;
if (surahNumber && ayatNumber) {
showSurahDetail(surahNumber, ayatNumber);
}
});
closeModal.addEventListener('click', () => {
surahModal.style.display = 'none';
});
window.onclick = function(event) {
if (event.target == surahModal) {
surahModal.style.display = 'none';
}
}
function displaySurahs(surahs) {
surahList.innerHTML = '';
surahs.forEach(surah => {
const listItem = document.createElement('li');
listItem.classList.add('cursor-pointer', 'p-4', 'bg-white', 'rounded-lg', 'shadow', 'hover:bg-gray-200');
listItem.innerHTML = `<i class="fas fa-book-open mr-2"></i> ${surah.nomor}. ${surah.namaLatin}`;
listItem.addEventListener('click', () => {
showSurahDetail(surah.nomor);
});
surahList.appendChild(listItem);
});
}
function populateSurahDropdown(surahs) {
surahSelect.innerHTML = '<option value="" selected>Pilih Surah</option>';
surahs.forEach(surah => {
const option = document.createElement('option');
option.value = surah.nomor;
option.textContent = `${surah.nomor}. ${surah.namaLatin}`;
surahSelect.appendChild(option);
});
}
function populateAyatDropdown(jumlahAyat) {
ayatSelect.innerHTML = '<option value="" selected>Pilih Ayat</option>';
for (let i = 1; i <= jumlahAyat; i++) {
const option = document.createElement('option');
option.value = i;
option.textContent = `Ayat ${i}`;
ayatSelect.appendChild(option);
}
}
function showSurahDetail(surahNumber, ayatNumber = null) {
fetch(`https://equran.id/api/v2/surat/${surahNumber}`)
.then(response => response.json())
.then(data => {
const surah = data.data;
surahName.textContent = `${surah.nomor}. ${surah.namaLatin} (${surah.nama})`;
surahInfo.innerHTML = `
<p><strong>Jumlah Ayat:</strong> ${surah.jumlahAyat}</p>
<p><strong>Tempat Turun:</strong> ${surah.tempatTurun}</p>
<p><strong>Arti:</strong> ${surah.arti}</p>
<p class="justify-text"><strong>Deskripsi:</strong> ${surah.deskripsi}</p>
`;
ayatList.innerHTML = '';
surah.ayat.forEach(ayat => {
if (!ayatNumber || ayat.nomorAyat == ayatNumber) {
const ayatItem = document.createElement('div');
ayatItem.classList.add('ayah', 'mb-4', 'p-2', 'bg-gray-100', 'rounded-lg');
ayatItem.innerHTML = `
<p class="ayat-number"><strong>Ayat ${ayat.nomorAyat}:</strong></p>
<p class="ayat-arab text-right">${ayat.teksArab}</p>
<p class="text-right">${ayat.teksLatin}</p>
<p>${ayat.teksIndonesia}</p>
<audio controls>
<source src="${ayat.audio['01']}" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<div class="mt-2">
<button class="share-button bg-blue-500 text-white px-4 py-2 rounded-md" data-ayat="${ayat.nomorAyat}" data-surah="${surah.nomor}">
Share Ayat
</button>
</div>
`;
ayatList.appendChild(ayatItem);
}
});
fetch(`https://equran.id/api/v2/tafsir/${surahNumber}`)
.then(response => response.json())
.then(data => {
tafsirList.innerHTML = '';
data.data.tafsir.forEach(tafsir => {
if (!ayatNumber || tafsir.ayat == ayatNumber) {
const tafsirItem = document.createElement('div');
tafsirItem.classList.add('tafsir', 'mb-4', 'p-2', 'bg-gray-100', 'rounded-lg');
tafsirItem.innerHTML = `
<p class="ayat-number"><strong>Ayat ${tafsir.ayat}:</strong></p>
<p class="justify-text">${tafsir.teks}</p>
`;
tafsirList.appendChild(tafsirItem);
}
});
})
.catch(error => console.error('Error fetching tafsir:', error));
surahModal.style.display = 'block';
// Event listener untuk tombol share
const shareButtons = document.querySelectorAll('.share-button');
shareButtons.forEach(button => {
button.addEventListener('click', function () {
const ayatNumber = this.getAttribute('data-ayat');
const surahNumber = this.getAttribute('data-surah');
const shareUrl = `${window.location.origin}${window.location.pathname}?surah=${surahNumber}&ayat=${ayatNumber}`;
const shareText = `Baca ayat ini dari Surah ${surahName.textContent}: ${shareUrl}`;
if (navigator.share) {
navigator.share({
title: 'Al-Qur\'an Web',
text: shareText,
url: shareUrl
}).then(() => {
console.log('Thanks for sharing!');
}).catch(err => {
console.error('Error sharing:', err);
});
} else {
// Fallback untuk browser yang tidak mendukung navigator.share
const dummy = document.createElement('textarea');
document.body.appendChild(dummy);
dummy.value = shareText;
dummy.select();
document.execCommand('copy');
document.body.removeChild(dummy);
alert('Link telah disalin ke clipboard');
}
});
});
})
.catch(error => console.error('Error fetching surah detail:', error));
}
// Populate Juz Dropdown
function populateJuzDropdown() {
juzSelect.innerHTML = '<option value="" selected>Pilih Juz</option>';
for (let i = 1; i <= 30; i++) {
const option = document.createElement('option');
option.value = i;
option.textContent = `Juz ${i}`;
juzSelect.appendChild(option);
}
}
populateJuzDropdown();
});
</script>
</body>
</html>