diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-07 00:23:45 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-07 00:23:45 +0300 |
| commit | a0603095a35473a6479beb612bc2ed7b33298260 (patch) | |
| tree | a4fe50996e1007f74290ff8cb922dc1daa7b77b0 /web/js/dom.js | |
| parent | d87bcee585883f22b2ca0b42db67bf815cc7c1fc (diff) | |
Task 61 extract frontend utilities
Diffstat (limited to 'web/js/dom.js')
| -rw-r--r-- | web/js/dom.js | 24 |
1 files changed, 2 insertions, 22 deletions
diff --git a/web/js/dom.js b/web/js/dom.js index 3d78bb4..1ea5840 100644 --- a/web/js/dom.js +++ b/web/js/dom.js @@ -1,3 +1,5 @@ +export { escapeHtml, fmtDur, toast } from './utils.js'; + export function fmtDate(d) { if (!d) return ''; const dt = typeof d === 'string' ? new Date(d) : d; @@ -11,16 +13,6 @@ export function fmtDateTime(d) { return dt.toLocaleString(); } -export function fmtDur(s) { - if (!s || s < 0) return '0:00'; - const h = Math.floor(s / 3600); - const m = Math.floor((s % 3600) / 60); - const sec = Math.floor(s % 60); - const mm = String(m).padStart(2, '0'); - const ss = String(sec).padStart(2, '0'); - return h > 0 ? `${h}:${mm}:${ss}` : `${mm}:${ss}`; -} - export function fmtSize(bytes) { if (!bytes || bytes <= 0) return ''; const kb = bytes / 1024; @@ -30,18 +22,6 @@ export function fmtSize(bytes) { return Math.round((mb / 1024) * 10) / 10 + ' GB'; } -export function escapeHtml(s) { - return (s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c])); -} - -export function toast(msg, type = 'info') { - const t = document.getElementById('toast'); - if (!t) return; - t.textContent = msg; - t.className = 'toast show ' + type; - setTimeout(() => t.classList.remove('show'), 2800); -} - export function closeAllModals() { document.querySelectorAll('.modal-overlay.open').forEach((m) => m.classList.remove('open')); } |
