Pembaruan UI Menu SK
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
{{-- JS bersama kolom Tentang. Di-include di dalam <script> tiap sub menu SK; panggil initKolomSk('#id-tabel') pada drawCallback DataTable. --}}
|
||||
// Dipanggil setiap tabel selesai digambar: tampilkan "Baca selengkapnya" bila teks terpotong, dan pasang dropdown salin
|
||||
function initKolomSk(tabelSelector) {
|
||||
document.querySelectorAll(tabelSelector + ' tbody .tentang-teks').forEach(function(el) {
|
||||
var link = el.parentElement.querySelector('.tentang-baca');
|
||||
if (link && el.scrollHeight > el.clientHeight + 1) {
|
||||
link.classList.remove('d-none');
|
||||
}
|
||||
});
|
||||
// Posisi fixed agar menu tidak terpotong oleh table-responsive
|
||||
document.querySelectorAll(tabelSelector + ' tbody .btn-salin-toggle').forEach(function(el) {
|
||||
bootstrap.Dropdown.getOrCreateInstance(el, { popperConfig: { strategy: 'fixed' } });
|
||||
});
|
||||
}
|
||||
|
||||
// Baca selengkapnya / Tutup untuk teks tentang (dengan animasi tinggi)
|
||||
$(document).on('click', '.tentang-baca', function() {
|
||||
var el = $(this).siblings('.tentang-teks')[0];
|
||||
var buka = el.dataset.open !== '1';
|
||||
el.dataset.open = buka ? '1' : '0';
|
||||
$(this).text(buka ? 'Tutup' : 'Baca selengkapnya ...');
|
||||
clearTimeout(el._tentangTimer);
|
||||
|
||||
var tinggiSekarang = el.offsetHeight;
|
||||
var tinggiTujuan;
|
||||
if (buka) {
|
||||
el.classList.add('expanded');
|
||||
tinggiTujuan = el.scrollHeight;
|
||||
} else {
|
||||
// Ukur tinggi saat terpotong 2 baris, lalu kembalikan ke kondisi terbuka untuk dianimasikan
|
||||
el.classList.remove('expanded');
|
||||
tinggiTujuan = el.clientHeight;
|
||||
el.classList.add('expanded');
|
||||
}
|
||||
|
||||
el.style.height = tinggiSekarang + 'px';
|
||||
void el.offsetHeight; // paksa reflow agar transisi berjalan
|
||||
el.style.height = tinggiTujuan + 'px';
|
||||
|
||||
el._tentangTimer = setTimeout(function() {
|
||||
el.style.height = '';
|
||||
if (!buka) { el.classList.remove('expanded'); }
|
||||
}, 320);
|
||||
});
|
||||
|
||||
// Salin teks (Nama Tentang / ID SK) ke clipboard
|
||||
function salinKeClipboard(teks) {
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
return navigator.clipboard.writeText(teks);
|
||||
}
|
||||
return new Promise(function(resolve, reject) {
|
||||
var ta = document.createElement('textarea');
|
||||
ta.value = teks;
|
||||
ta.style.position = 'fixed';
|
||||
ta.style.opacity = '0';
|
||||
document.body.appendChild(ta);
|
||||
ta.select();
|
||||
try {
|
||||
document.execCommand('copy') ? resolve() : reject();
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
} finally {
|
||||
document.body.removeChild(ta);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(document).on('click', '.btn-salin', function() {
|
||||
var teks = $(this).attr('data-salin') || '';
|
||||
var label = $(this).data('label');
|
||||
salinKeClipboard(teks).then(function() {
|
||||
showSuccess('Berhasil', label + ' berhasil disalin.');
|
||||
}).catch(function() {
|
||||
showError('Gagal', 'Tidak dapat menyalin ' + label + '.');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user