mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 12:39:53 +01:00
Implement frontpage theme switch
This commit is contained in:
parent
f0c7fdb92f
commit
6ad7b1d599
3 changed files with 25 additions and 1 deletions
|
@ -12,6 +12,7 @@ import initQuestion from 'retrospring/features/question';
|
|||
import initModeration from 'retrospring/features/moderation';
|
||||
import initMemes from 'retrospring/features/memes';
|
||||
import initLocales from 'retrospring/features/locales';
|
||||
import initFront from 'retrospring/features/front';
|
||||
|
||||
start();
|
||||
document.addEventListener('DOMContentLoaded', initAnswerbox);
|
||||
|
@ -24,4 +25,5 @@ document.addEventListener('DOMContentLoaded', initQuestion);
|
|||
document.addEventListener('DOMContentLoaded', initModeration);
|
||||
document.addEventListener('DOMContentLoaded', initMemes);
|
||||
document.addEventListener('turbolinks:load', initAnnouncements);
|
||||
document.addEventListener('turbolinks:load', initLocales);
|
||||
document.addEventListener('turbolinks:load', initLocales);
|
||||
document.addEventListener('turbolinks:load', initFront);
|
8
app/javascript/retrospring/features/front/index.ts
Normal file
8
app/javascript/retrospring/features/front/index.ts
Normal 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 }
|
||||
]);
|
||||
}
|
14
app/javascript/retrospring/features/front/theme.ts
Normal file
14
app/javascript/retrospring/features/front/theme.ts
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue