Skip to content

Commit

Permalink
[pre-commit.ci lite] apply automatic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci-lite[bot] authored Feb 4, 2024
1 parent 7405b99 commit 35b9a7e
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions src/main/resources/static/theme-toggle.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
(function () {
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
let initialTheme
if (localStorage.getItem('darkmode-pref-set') === 'true') {
initialTheme = localStorage.getItem('darkMode') === 'true'
} else {
initialTheme = darkModeMediaQuery.matches
}
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
let initialTheme
if (localStorage.getItem('darkmode-pref-set') === 'true') {
initialTheme = localStorage.getItem('darkMode') === 'true'
} else {
initialTheme = darkModeMediaQuery.matches
}

function updateToggle (darkMode) {
document.querySelector(".theme-toggle input[type=radio][value='dark']").checked = darkMode
document.querySelector(".theme-toggle input[type=radio][value='light']").checked = !darkMode
function updateToggle (darkMode) {
document.querySelector(".theme-toggle input[type=radio][value='dark']").checked = darkMode
document.querySelector(".theme-toggle input[type=radio][value='light']").checked = !darkMode

document.body.classList.toggle('dark-mode', darkMode)
localStorage.setItem('darkMode', darkMode)
localStorage.setItem('darkmode-pref-set', 'true')
}
document.body.classList.toggle('dark-mode', darkMode)
localStorage.setItem('darkMode', darkMode)
localStorage.setItem('darkmode-pref-set', 'true')
}

darkModeMediaQuery.addEventListener('change', (e) => {
const darkModeOn = e.matches
updateToggle(darkModeOn)
})

window.addEventListener('load', function () {
const radios = document.querySelectorAll('.theme-toggle input[type=radio]')
radios.forEach((radio) => {
radio.addEventListener('change', function (e) {
updateToggle(e.target.value === 'dark')
})
})
darkModeMediaQuery.addEventListener('change', (e) => {
const darkModeOn = e.matches
updateToggle(darkModeOn)
})

updateToggle(initialTheme)
window.addEventListener('load', function () {
const radios = document.querySelectorAll('.theme-toggle input[type=radio]')
radios.forEach((radio) => {
radio.addEventListener('change', function (e) {
updateToggle(e.target.value === 'dark')
})
})

updateToggle(initialTheme)
})
})()

0 comments on commit 35b9a7e

Please sign in to comment.