summaryrefslogtreecommitdiffstats
path: root/assets/js/theme-switch.js
blob: 148ef26e003e8a81bfca72e99a4ef166489f4a09 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
    jtd.setTheme('dark'); 
} else {
    jtd.setTheme('light'); 
}

window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
    const newColorScheme = event.matches ? "dark" : "light";
    jtd.setTheme(newColorScheme);
});


const toggleDarkMode = document.querySelector('.js-toggle-dark-mode'); 
jtd.addEvent(toggleDarkMode, 'click', function(){ 
    if (jtd.getTheme() === 'dark') { 
        jtd.setTheme('light'); 
        toggleDarkMode.textContent = 'Preview dark color scheme'; 
    } else { jtd.setTheme('dark'); 
    toggleDarkMode.textContent = 'Return to the light side'; } 
});