(function() { 'use strict'; // Project-picker dropdown for the archive browser. // // In multi-project mode (HTTP source against zddc-server, OR ?projects= // present in the URL), this dropdown lets the user toggle which projects // are scanned. Toggling a checkbox updates window.app.projectFilter, pushes // the new ?projects= state to the URL, and triggers a re-scan. // // In single-project mode the dropdown is hidden — only one project is ever // in scope, so picking is meaningless. let isOpen = false; // The set of project names currently shown in the dropdown. function getKnownProjects() { if (window.app.availableProjects && window.app.availableProjects.length > 0) { return window.app.availableProjects.slice(); } // Fall back to whatever is in the URL filter — useful when the server's // ProjectInfo endpoint isn't reachable but ?projects= names the set. return Array.from(window.app.projectFilter || []); } // Visibility-only filter: change visibleProjects, push URL state, re-render // UI. No rescan — already-scanned data stays in memory. URL is updated via // history.replaceState (same mechanism as every other UI control). function applyVisibility(names) { window.app.visibleProjects = new Set(names); window.app.modules.urlState.push(); window.app.modules.app.updateUI(); window.app.modules.filtering.applyFilters(); renderDropdown(); } function escapeHtml(text) { var div = document.createElement('div'); div.textContent = text; return div.innerHTML; } function renderDropdown() { var dropdown = document.getElementById('presetDropdown'); if (!dropdown) return; var selected = new Set(window.app.visibleProjects || []); var known = getKnownProjects().slice().sort(); // Show the human-friendly title from each project's .zddc // when present (captured during auto-detect into // window.app.projectTitles), falling back to the folder name. // The data-name attribute always carries the canonical folder // name so URL state stays stable regardless of label. var titles = window.app.projectTitles || {}; var projectsHtml = known.map(name => { var checked = selected.has(name) ? ' checked' : ''; var label = titles[name] || name; var nAttr = escapeHtml(name); var nLabel = escapeHtml(label); var hint = (label !== name) ? ' (' + escapeHtml(name) + ')' : ''; return '