From 8952855edecb0d44d4429eeed4012ffd01cd810e Mon Sep 17 00:00:00 2001 From: zzossig Date: Sun, 25 Oct 2020 01:03:43 +0900 Subject: enableDarkMode bug fix fix #24 --- layouts/partials/head/scripts.html | 31 ++++++++++++++++++++----------- 1 file 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) { -- cgit v1.2.3