summaryrefslogtreecommitdiffstats
path: root/dist/js/lib/themes.js
diff options
context:
space:
mode:
authorrstular <rok@stular.eu>2020-05-17 16:14:07 +0200
committerrstular <rok@stular.eu>2020-05-17 16:29:20 +0200
commit831563c8ecb2854ceba73c284719b7579c0a3bbc (patch)
tree597d4f2d8a184c13e05027c9ce877d203686c015 /dist/js/lib/themes.js
parentMerge branch 'dev' of github.com:beziapp/beziapp.github.io into dev (diff)
downloadbeziapp-831563c8ecb2854ceba73c284719b7579c0a3bbc.tar
beziapp-831563c8ecb2854ceba73c284719b7579c0a3bbc.tar.gz
beziapp-831563c8ecb2854ceba73c284719b7579c0a3bbc.tar.bz2
beziapp-831563c8ecb2854ceba73c284719b7579c0a3bbc.tar.lz
beziapp-831563c8ecb2854ceba73c284719b7579c0a3bbc.tar.xz
beziapp-831563c8ecb2854ceba73c284719b7579c0a3bbc.tar.zst
beziapp-831563c8ecb2854ceba73c284719b7579c0a3bbc.zip
Diffstat (limited to '')
-rw-r--r--dist/js/lib/themes.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/dist/js/lib/themes.js b/dist/js/lib/themes.js
new file mode 100644
index 0000000..d8a7ca1
--- /dev/null
+++ b/dist/js/lib/themes.js
@@ -0,0 +1,37 @@
+const THEME_COLOR_SCHEMES = {
+ light: {
+ "color-primary": "rgba(0, 128, 83, 1)",
+ "color-secondary": "rgba(0, 77, 50, 1)",
+ "color-accent": "rgba(0, 156, 101, 1)",
+ "color-primary-light": "rgba(230, 250, 231, 1)",
+ "color-invalid": "rgba(192, 0, 0, 1)",
+ "background-color": "rgba(255, 255, 255, 1)",
+ "background-accent": "rgba(0, 156, 101, 0.2)"
+ },
+ dark: {
+ "color-primary": "rgba(0, 128, 83, 1)",
+ "color-secondary": "rgba(0, 94, 61, 1)",
+ "color-accent": "rgba(20, 117, 83, 1)",
+ "color-primary-light": "rgba(230, 250, 231, 1)",
+ "color-invalid": "rgba(192, 0, 0, 1)",
+ "background-color": "rgba(31, 31, 31, 1)",
+ "background-accent": "rgba(0, 92, 44, 0.2)"
+ }
+}
+
+function applyTheme(themeName) {
+ for (const [property, value] of Object.entries(THEME_COLOR_SCHEMES[themeName])) {
+ document.documentElement.style.setProperty(`--${property}`, value);
+ }
+}
+
+document.addEventListener("DOMContentLoaded", () => {
+ localforage.getItem("theme").then((selectedTheme) => {
+ if (selectedTheme == null) {
+ let isOsDarkTheme = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
+ applyTheme(isOsDarkTheme ? "dark" : "light");
+ } else {
+ applyTheme(selectedTheme);
+ }
+ });
+}); \ No newline at end of file