28 lines
1.6 KiB
JavaScript
28 lines
1.6 KiB
JavaScript
/* EasyDNS UI progressive enhancements. No secrets, auth state or API tokens in JS. */
|
|
(() => {
|
|
'use strict';
|
|
const side = document.getElementById('sidebar');
|
|
const toggle = document.getElementById('menuToggle');
|
|
const cover = document.getElementById('sidebarOverlay');
|
|
const close = () => { side?.classList.remove('open'); cover?.classList.remove('open'); toggle?.setAttribute('aria-expanded', 'false'); };
|
|
toggle?.addEventListener('click', () => {const on = side.classList.toggle('open');cover?.classList.toggle('open', on);toggle.setAttribute('aria-expanded', String(on));});
|
|
cover?.addEventListener('click', close);
|
|
document.addEventListener('keydown', e => {if(e.key === 'Escape') close();});
|
|
document.querySelectorAll('.notice-dismiss').forEach(el => el.addEventListener('click', () => el.closest('.notice')?.remove()));
|
|
// Strict CSP disallows inline onchange handlers. The server selector
|
|
// submits the CSRF-protected form immediately on selection change.
|
|
document.querySelectorAll('select[data-switch-server]').forEach(select => {
|
|
select.addEventListener('change', () => {
|
|
if (!select.form || !select.value) return;
|
|
if (typeof select.form.requestSubmit === 'function') select.form.requestSubmit();
|
|
else select.form.submit();
|
|
});
|
|
});
|
|
document.querySelectorAll('.bar-fill[data-count]').forEach(bar => {
|
|
const count = Number(bar.dataset.count), total = Number(bar.dataset.total);
|
|
const ratio = Number.isFinite(count) && Number.isFinite(total) && total > 0 ? 100 * count / total : 0;
|
|
bar.style.width = Math.max(0, Math.min(100, ratio)) + '%';
|
|
bar.title = ratio.toFixed(1) + '% of total';
|
|
});
|
|
})();
|