Implement frontpage theme switch

This commit is contained in:
Andreas Nedbal 2022-04-10 02:37:54 +02:00 committed by Andreas Nedbal
parent f0c7fdb92f
commit 6ad7b1d599
3 changed files with 25 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import initQuestion from 'retrospring/features/question';
import initModeration from 'retrospring/features/moderation'; import initModeration from 'retrospring/features/moderation';
import initMemes from 'retrospring/features/memes'; import initMemes from 'retrospring/features/memes';
import initLocales from 'retrospring/features/locales'; import initLocales from 'retrospring/features/locales';
import initFront from 'retrospring/features/front';
start(); start();
document.addEventListener('DOMContentLoaded', initAnswerbox); document.addEventListener('DOMContentLoaded', initAnswerbox);
@ -25,3 +26,4 @@ document.addEventListener('DOMContentLoaded', initModeration);
document.addEventListener('DOMContentLoaded', initMemes); document.addEventListener('DOMContentLoaded', initMemes);
document.addEventListener('turbolinks:load', initAnnouncements); document.addEventListener('turbolinks:load', initAnnouncements);
document.addEventListener('turbolinks:load', initLocales); document.addEventListener('turbolinks:load', initLocales);
document.addEventListener('turbolinks:load', initFront);

View File

@ -0,0 +1,8 @@
import registerEvents from 'retrospring/utilities/registerEvents';
import { themeButtonHandler } from './theme';
export default (): void => {
registerEvents([
{ type: 'click', target: document.querySelectorAll('.js-theme-button'), handler: themeButtonHandler }
]);
}

View File

@ -0,0 +1,14 @@
export function themeButtonHandler(event: Event): void {
const button = event.currentTarget as HTMLButtonElement;
event.preventDefault();
const theme = button.dataset.theme;
document.body.setAttribute('class', 'not-logged-in');
if (theme === 'reset') return;
if (!document.body.classList.contains(theme)) {
document.body.classList.add(theme);
}
}