New Version - 1.0.1 — Set dark theme as default & fix eslint

This commit is contained in:
panr 2018-08-24 09:37:55 +02:00
parent b442ae90c9
commit a8b843adb8
6 changed files with 113 additions and 52 deletions

View file

@ -1,12 +1,16 @@
// Toggle theme
const getTheme = localStorage.getItem('theme')
const getTheme = window.localStorage && window.localStorage.getItem('theme')
const themeToggle = document.querySelector('.theme-toggle')
const isDark = getTheme === 'dark'
const isDark = getTheme === 'dark' || getTheme === null
document.body.classList.toggle('dark-theme', isDark)
themeToggle.addEventListener('click', () => {
document.body.classList.toggle('dark-theme')
localStorage.setItem('theme', document.body.classList.contains('dark-theme') ? 'dark' : 'light')
})
window.localStorage &&
window.localStorage.setItem(
'theme',
document.body.classList.contains('dark-theme') ? 'dark' : 'light',
)
})