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:
-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) {