Implement frontpage theme switch
This commit is contained in:
parent
f0c7fdb92f
commit
6ad7b1d599
|
@ -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);
|
|
@ -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 }
|
||||||
|
]);
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue