Files
Pigmento/js/app.js
Ferdinand f70d02d11d feat: Tab-Navigation als Hamburger-Menü
3-Striche-Button öffnet Dropdown mit allen Kategorien.
Aktive Kategorie wird neben dem Button angezeigt.
Klick außerhalb schließt das Menü.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-03 17:04:02 +02:00

57 lines
2.2 KiB
JavaScript

import { initEingabe } from './eingabe.js';
import { initPicker } from './picker.js';
import { initHarmonien } from './harmonien.js';
import { addFavorit, addColorToSchema, addToHistory, renderSammlung, exportCollection, importCollection, saveSchema, setEditSchemaHandler } from './collection.js';
import { initSchemaModal, openForEdit } from './schema-modal.js';
// state.color is read-only from outside — always use setColor() to update,
// so that the colorChanged event is dispatched to all listening modules.
export const state = {
color: { h: 200, s: 60, l: 50 },
setColor(hsl) {
if (!hsl || typeof hsl.h !== 'number' || typeof hsl.s !== 'number' || typeof hsl.l !== 'number') return;
this.color = hsl;
document.dispatchEvent(new CustomEvent('colorChanged', { detail: hsl }));
}
};
// Hamburger-Menü
const menuToggle = document.getElementById('menu-toggle');
const menuDropdown = document.getElementById('menu-dropdown');
const menuActiveLabel = document.getElementById('menu-active-label');
menuToggle.addEventListener('click', (e) => {
e.stopPropagation();
menuDropdown.classList.toggle('open');
});
document.addEventListener('click', () => menuDropdown.classList.remove('open'));
// Tab-Navigation
document.querySelectorAll('.tab-btn').forEach(btn => {
btn.addEventListener('click', () => {
const tab = btn.dataset.tab;
document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
document.querySelectorAll('.tab-content').forEach(s => s.classList.remove('active'));
btn.classList.add('active');
const section = document.getElementById('tab-' + tab);
if (section) section.classList.add('active');
menuActiveLabel.textContent = btn.textContent;
menuDropdown.classList.remove('open');
});
});
// Every color change goes into history
document.addEventListener('colorChanged', (e) => addToHistory(e.detail));
initEingabe(addFavorit, addColorToSchema);
initPicker(addFavorit, addColorToSchema);
initHarmonien(addFavorit, addColorToSchema);
document.getElementById('sammlung-export-btn').addEventListener('click', exportCollection);
document.getElementById('sammlung-import-btn').addEventListener('click', importCollection);
renderSammlung();
initSchemaModal(saveSchema);
setEditSchemaHandler(openForEdit);