Files
EasyDNS-Web/internal/server/web/static/app.js
T
Mateusz Gruszczyński a28362b82c
Go quality gates / test (push) Waiting to run
v0.1.2
2026-12-01 00:16:15 +01:00

37 lines
2.1 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();
});
});
// DNSSEC exclusion is applied server-side, before pagination. Submit the
// current record filters without resetting name/type choices.
document.querySelectorAll('input[data-record-filter-toggle]').forEach(input => {
input.addEventListener('change', () => {
if (!input.form) return;
if (typeof input.form.requestSubmit === 'function') input.form.requestSubmit();
else input.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';
});
})();