summaryrefslogtreecommitdiffstats
path: root/assets/js/theme-switch.js
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--assets/js/theme-switch.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/assets/js/theme-switch.js b/assets/js/theme-switch.js
new file mode 100644
index 0000000..148ef26
--- /dev/null
+++ b/assets/js/theme-switch.js
@@ -0,0 +1,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'; }
+}); \ No newline at end of file