refactor(ui): step4 - extract ui.js (setText, showStatus, clearStatus, h, formatTimestamp, timestampCell)
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
/* ui.js — UI-вспомогательные функции */
|
||||
|
||||
function setText(id, value) {
|
||||
document.getElementById(id).textContent = String(value);
|
||||
}
|
||||
|
||||
function showStatus(message, kind) {
|
||||
const el = document.getElementById('status');
|
||||
el.style.display = 'block';
|
||||
el.className = 'status ' + (kind || '');
|
||||
el.textContent = message;
|
||||
}
|
||||
|
||||
function clearStatus() {
|
||||
const el = document.getElementById('status');
|
||||
el.style.display = 'none';
|
||||
el.className = 'status';
|
||||
el.textContent = '';
|
||||
}
|
||||
|
||||
function h(v) {
|
||||
return String(v == null ? '' : v)
|
||||
.replaceAll('&', '&')
|
||||
.replaceAll('<', '<')
|
||||
.replaceAll('>', '>')
|
||||
.replaceAll('"', '"')
|
||||
.replaceAll("'", ''');
|
||||
}
|
||||
|
||||
function formatTimestamp(ts) {
|
||||
if (!ts) return '—';
|
||||
var d = new Date(ts);
|
||||
if (isNaN(d.getTime())) return String(ts);
|
||||
return d.toLocaleString('ru-RU', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit'
|
||||
});
|
||||
}
|
||||
|
||||
function timestampCell(ts) {
|
||||
var text = formatTimestamp(ts);
|
||||
return '<span class="mono" title="' + h(ts || '') + '">' + h(text) + '</span>';
|
||||
}
|
||||
Reference in New Issue
Block a user