From 3f4aa41a685ccab17e1d76cdde20a4a6ab95a095 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Mon, 13 Jan 2020 19:41:52 +0100 Subject: Colortheme switcher --- themes/elenq/static/js/colorscheme-switcher.js | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 themes/elenq/static/js/colorscheme-switcher.js (limited to 'themes/elenq/static/js/colorscheme-switcher.js') 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); -- cgit v1.2.3