asdasd
This commit is contained in:
@@ -24,6 +24,27 @@ function pickDefaultSection(sections) {
|
||||
export async function initTabs() {
|
||||
const nav = document.getElementById('sectionTabs');
|
||||
if (!nav) return;
|
||||
|
||||
const setActive = (sections, id) => {
|
||||
const next = sections.find(s => Number(s.id) === Number(id));
|
||||
if (!next) return;
|
||||
window.__activeSection = next;
|
||||
renderTabs(nav, sections, next.id);
|
||||
if (typeof window.loadList === 'function') {
|
||||
window.loadList(next);
|
||||
}
|
||||
};
|
||||
|
||||
nav.addEventListener('click', (ev) => {
|
||||
const btn = ev.target?.closest?.('button[data-section-id]');
|
||||
if (!btn) return;
|
||||
const sections = window.__sectionsConfig || [];
|
||||
if (!sections.length) return;
|
||||
const id = Number(btn.dataset.sectionId || 0);
|
||||
if (!id) return;
|
||||
setActive(sections, id);
|
||||
});
|
||||
|
||||
const readyPromise = (async () => {
|
||||
try {
|
||||
const res = await apiAction('sections_config.list', { method: 'GET' });
|
||||
@@ -36,18 +57,6 @@ export async function initTabs() {
|
||||
const active = pickDefaultSection(sections);
|
||||
window.__activeSection = active;
|
||||
renderTabs(nav, sections, active?.id);
|
||||
nav.querySelectorAll('button[data-section-id]').forEach(btn => {
|
||||
btn.addEventListener('click', () => {
|
||||
const id = Number(btn.dataset.sectionId || 0);
|
||||
const next = sections.find(s => Number(s.id) === id);
|
||||
if (!next) return;
|
||||
window.__activeSection = next;
|
||||
renderTabs(nav, sections, next.id);
|
||||
if (typeof window.loadList === 'function') {
|
||||
window.loadList(next);
|
||||
}
|
||||
});
|
||||
});
|
||||
if (typeof window.loadList === 'function' && active) {
|
||||
window.loadList(active);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user