From 223d198c95b64d3d803be5d914c5b899dd30c8eb Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Mon, 13 Jul 2026 19:59:34 -0400 Subject: refactor(admin): simplify css and js of card collapsing and side bar directories --- internal/admin/static/editor.js | 53 +++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 20 deletions(-) (limited to 'internal/admin/static/editor.js') diff --git a/internal/admin/static/editor.js b/internal/admin/static/editor.js index 593bf7f..7a4fcb1 100644 --- a/internal/admin/static/editor.js +++ b/internal/admin/static/editor.js @@ -3,7 +3,7 @@ var editorFields = []; var currentID = null; var allIDs = []; var treeData = { root: [], dirs: {} }; -var collapsedDirs = {}; +var dirOpenState = {}; function initEditor(type, fields) { editorType = type; @@ -49,6 +49,12 @@ function renderList(filter) { } el.innerHTML = html; + el.querySelectorAll('details.dir-group').forEach(function(d) { + d.addEventListener('toggle', function() { + var n = d.getAttribute('data-name'); + if (n) dirOpenState[n] = d.open; + }); + }); } function renderDirGroup(name, ids, filter) { @@ -59,30 +65,37 @@ function renderDirGroup(name, ids, filter) { displayIds = ids.filter(function(id) { return String(id).toLowerCase().indexOf(filter) >= 0; }); if (displayIds.length === 0) return ''; } - var expanded = isFiltering ? true : (collapsedDirs[name] === true); - var displayName = name || editorType.charAt(0).toUpperCase() + editorType.slice(1); - var h = '
'; - if (name) { - h += '
'; - h += '' + (expanded ? '▼' : '▶') + ''; - h += '' + esc(displayName) + ''; - h += '' + (isFiltering ? displayIds.length + '/' + ids.length : ids.length) + ''; - h += '
'; + + function renderItems() { + var h = ''; + displayIds.forEach(function(id) { + h += '
' + esc(id) + '
'; + }); + return h; } - h += ''; + + if (!name) { + var fh = '
'; + fh += renderItems(); + fh += '
'; + return fh; + } + + var open = isFiltering || dirOpenState[name] === true; + var openAttr = open ? ' open' : ''; + var h = '
'; + h += ''; + h += ''; + h += '' + esc(name) + ''; + h += '' + (isFiltering ? displayIds.length + '/' + ids.length : ids.length) + ''; + h += ''; + h += '
'; + h += renderItems(); h += '
'; + h += '
'; return h; } -function toggleDir(name) { - collapsedDirs[name] = collapsedDirs[name] !== true; - renderList(''); -} - function filterList(val) { renderList(val); } -- cgit v1.2.3