Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zzossig/hugo-theme-zdoc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzzossig <zzossig@gmail.com>2020-10-24 19:03:43 +0300
committerzzossig <zzossig@gmail.com>2020-10-24 19:03:43 +0300
commit8952855edecb0d44d4429eeed4012ffd01cd810e (patch)
tree7c7a9bd30184b4c71f2702d0201f2450565c2d53
parent5cb148bab9a190431dab408d375b99843d59a7c5 (diff)
enableDarkMode bug fix
fix #24
-rw-r--r--layouts/partials/head/scripts.html31
1 files changed, 20 insertions, 11 deletions
diff --git a/layouts/partials/head/scripts.html b/layouts/partials/head/scripts.html
index c6184c0..22dec7f 100644
--- a/layouts/partials/head/scripts.html
+++ b/layouts/partials/head/scripts.html
@@ -219,27 +219,36 @@
}) : null;
// =============================================================
-
// ======================= toggle theme =======================
+ {{ $enableDarkMode := ($.Param "enableDarkMode") }}
+ var enableDarkMode = JSON.parse({{ $enableDarkMode | jsonify }});
var root = document.getElementById('root');
var toggleToLightBtn = document.getElementById('toggleToLight');
var toggleToDarkBtn = document.getElementById('toggleToDark');
- toggleToDark.onclick = function(e) {
- root.className = 'theme__dark';
- localStorage.setItem('theme', 'dark');
- toggleToLightBtn.className = 'navbar__icons--icon';
- toggleToDarkBtn.className = 'hide';
- }
-
- toggleToLight.onclick = function (e) {
+ if (!enableDarkMode) {
root.className = 'theme__light';
localStorage.setItem('theme', 'light');
- toggleToLightBtn.className = 'hide';
- toggleToDarkBtn.className = 'navbar__icons--icon';
+ }
+
+ if (toggleToDarkBtn) {
+ toggleToDarkBtn.onclick = function (e) {
+ root.className = 'theme__dark';
+ localStorage.setItem('theme', 'dark');
+ toggleToLightBtn.className = 'navbar__icons--icon';
+ toggleToDarkBtn.className = 'hide';
+ }
}
+ if (toggleToLightBtn) {
+ toggleToLightBtn.onclick = function (e) {
+ root.className = 'theme__light';
+ localStorage.setItem('theme', 'light');
+ toggleToLightBtn.className = 'hide';
+ toggleToDarkBtn.className = 'navbar__icons--icon';
+ }
+ }
// =================== section menu collapse ==================
document.querySelectorAll('.menu__list').forEach(function(elem) {