topbar anpassungen
This commit is contained in:
@@ -14,18 +14,24 @@ const setIcon = (button, contrast) => {
|
||||
icon.classList.add(contrast === 'high' ? 'bi-highlights' : 'bi-circle-half');
|
||||
};
|
||||
|
||||
const setPressedState = (button, contrast) => {
|
||||
button.setAttribute('aria-pressed', contrast === 'high' ? 'true' : 'false');
|
||||
};
|
||||
|
||||
const initContrastToggle = () => {
|
||||
const button = requireEl('[data-contrast-toggle]', { module: 'contrast-toggle' });
|
||||
if (!button) {return;}
|
||||
const root = document.documentElement;
|
||||
const getCurrent = () => (root.dataset.contrast === 'high' ? 'high' : 'normal');
|
||||
setIcon(button, getCurrent());
|
||||
const current = getCurrent();
|
||||
setIcon(button, current);
|
||||
setPressedState(button, current);
|
||||
|
||||
button.addEventListener('click', () => {
|
||||
const current = getCurrent();
|
||||
const next = current === 'high' ? 'normal' : 'high';
|
||||
const next = getCurrent() === 'high' ? 'normal' : 'high';
|
||||
setContrast(next);
|
||||
setIcon(button, next);
|
||||
setPressedState(button, next);
|
||||
try {
|
||||
window.localStorage.setItem(STORAGE_KEY, next);
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user