summaryrefslogtreecommitdiff
path: root/themes/elenq/static/js
diff options
context:
space:
mode:
Diffstat (limited to 'themes/elenq/static/js')
-rw-r--r--themes/elenq/static/js/colorscheme-switcher.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/themes/elenq/static/js/colorscheme-switcher.js b/themes/elenq/static/js/colorscheme-switcher.js
new file mode 100644
index 0000000..889b0dd
--- /dev/null
+++ b/themes/elenq/static/js/colorscheme-switcher.js
@@ -0,0 +1,35 @@
+var theme_switch = document.getElementById("dark-light-switch");
+
+var body = document.getElementsByTagName("BODY")[0];
+
+function init( color ){
+ theme_switch.setAttribute("color", color);
+ document.getElementById("dark-light-switch");
+}
+
+
+function change(color){
+ window.setTimeout(function() {
+ document.documentElement.classList.remove('color-theme-in-transition')
+ }, 1000)
+ document.documentElement.classList.add('color-theme-in-transition');
+ document.documentElement.setAttribute('data-theme', color);
+ theme_switch.setAttribute("color", color);
+}
+
+function theme_changed(){
+ color = theme_switch.getAttribute("color");
+ if(color=="light")
+ change("dark");
+ else
+ change("light");
+}
+
+var background = getComputedStyle(body).getPropertyValue("background-color");
+if(background == "rgb(255, 255, 255)") {
+ init("light");
+} else {
+ init("dark");
+}
+theme_switch.addEventListener("click", theme_changed);
+theme_switch.addEventListener("touch", theme_changed);