2018-07-20 19:14:22 +02:00
|
|
|
// Toggle theme
|
|
|
|
|
2018-08-24 09:37:55 +02:00
|
|
|
const getTheme = window.localStorage && window.localStorage.getItem('theme')
|
2018-07-20 19:14:22 +02:00
|
|
|
const themeToggle = document.querySelector('.theme-toggle')
|
2018-08-24 09:37:55 +02:00
|
|
|
const isDark = getTheme === 'dark' || getTheme === null
|
2018-07-20 19:14:22 +02:00
|
|
|
|
|
|
|
document.body.classList.toggle('dark-theme', isDark)
|
|
|
|
|
|
|
|
themeToggle.addEventListener('click', () => {
|
|
|
|
document.body.classList.toggle('dark-theme')
|
2018-08-24 09:37:55 +02:00
|
|
|
window.localStorage &&
|
|
|
|
window.localStorage.setItem(
|
|
|
|
'theme',
|
|
|
|
document.body.classList.contains('dark-theme') ? 'dark' : 'light',
|
|
|
|
)
|
|
|
|
})
|