Skip to content
This repository has been archived by the owner on Apr 27, 2022. It is now read-only.

Commit

Permalink
hot-fix: add error when internet disconnect or when something wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
dikisiswanto committed Apr 24, 2020
1 parent a54cf4e commit 9b890e6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 30 deletions.
69 changes: 41 additions & 28 deletions assets/js/widget.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,49 @@
$(document).ready(function () {
if ($('#jadwal-shalat').length) {

const BASE_API_URL = 'https://api.banghasan.com/';
const endpoint_nama_kota = `sholat/format/json/kota/kode/${KODE_KOTA}`;
const endpoint_jadwal = `sholat/format/json/jadwal/kota/${KODE_KOTA}/tanggal/${TANGGAL}`;

// get nama kota
$.ajax({
url: BASE_API_URL + endpoint_nama_kota,
type: 'get',
dataType: 'json',
crossDomain: true,
success: function (res) {
$('[data-name=kota]').html(res.kota[0].nama).removeClass('shimmer line-short');
}
});

// get jadwal sholat
$.ajax({
url: BASE_API_URL + endpoint_jadwal,
type: 'get',
dataType: 'json',
crossDomain: true,
success: function (res) {
$('.shimmer').removeClass('shimmer');
$('[data-name=imsak]').html(`<span class="small text-bold">Imsak</span><span>${res.jadwal.data.imsak}</span>`);
$('[data-name=subuh]').html(`<span class="small text-bold">Subuh</span><span>${res.jadwal.data.subuh}</span>`);
$('[data-name=dzuhur]').html(`<span class="small text-bold">Dzuhur</span><span>${res.jadwal.data.dzuhur}</span>`);
$('[data-name=ashar]').html(`<span class="small text-bold">Ashar</span><span>${res.jadwal.data.ashar}</span>`);
$('[data-name=maghrib]').html(`<span class="small text-bold">Maghrib</span><span>${res.jadwal.data.maghrib}</span>`);
$('[data-name=isya]').html(`<span class="small text-bold">Isya</span><span>${res.jadwal.data.isya}</span>`);
}
})
try {
// get nama kota
$.ajax({
url: BASE_API_URL + endpoint_nama_kota,
type: 'get',
dataType: 'json',
crossDomain: true,
success: function (res) {
$('[data-name=kota]').html(res.kota[0].nama).removeClass('shimmer line-short');
},
error: function (err) {
$('.line-short').html(`<span class="small"><i class="fa fa-exclamation-triangle pr-1"></i> Gagal memuat</span>`);
$('.line-short').removeClass('shimmer line-short');
}
});

// get jadwal sholat
$.ajax({
url: BASE_API_URL + endpoint_jadwal,
type: 'get',
dataType: 'json',
crossDomain: true,
success: function (res) {
$('.shimmer').removeClass('shimmer');
$('[data-name=imsak]').html(`<span class="small">Imsak</span><span>${res.jadwal.data.imsak}</span>`);
$('[data-name=subuh]').html(`<span class="small">Subuh</span><span>${res.jadwal.data.subuh}</span>`);
$('[data-name=dzuhur]').html(`<span class="small">Dzuhur</span><span>${res.jadwal.data.dzuhur}</span>`);
$('[data-name=ashar]').html(`<span class="small">Ashar</span><span>${res.jadwal.data.ashar}</span>`);
$('[data-name=maghrib]').html(`<span class="small">Maghrib</span><span>${res.jadwal.data.maghrib}</span>`);
$('[data-name=isya]').html(`<span class="small">Isya</span><span>${res.jadwal.data.isya}</span>`);
},
error: function (err) {
$('.box-shalat').html(`<span class="small"><i class="fa fa-exclamation-triangle pr-1"></i> Gagal memuat</span>`);
$('.box-shalat').removeClass('shimmer');
}
});
} catch(err) {
console.log(err);
}

}
})
2 changes: 1 addition & 1 deletion assets/js/widget.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion widgets/jadwal_shalat.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
const KODE_KOTA = "<?= config_item('kode_kota') ?: JAKARTA ?>";
const TANGGAL = "<?= date('Y-m-d') ?>";
</script>
<script src="<?= base_url("$this->theme_folder/$this->theme/assets/js/widget.js") ?>"></script>
<script src="<?= base_url("$this->theme_folder/$this->theme/assets/js/widget.min.js") ?>"></script>

<section id="jadwal-shalat" class="py-4 bg-white">
<div class="container">
Expand Down

0 comments on commit 9b890e6

Please sign in to comment.