ybbond

My site. The main domain
Log | Files | Refs | README | LICENSE | CC-LICENSE

commit 6e2b18aebc810e61bcbd69bb1358faa8397cf714
parent 36f20f0a4b88d9344a8c234c932fcd7c86836337
Author: Yohanes Bandung <bandungpenting@gmail.com>
Date:   Wed, 29 Apr 2020 00:24:46 +0700

hotfix: theme toggler absolute path

Diffstat:
Mlayouts/partials/head/head.html | 2+-
Mstatic/darkToggler.js | 13+++++++++++--

2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/layouts/partials/head/head.html b/layouts/partials/head/head.html
@@ -24,7 +24,7 @@
   {{ end }}
 </style>
 
-<script type="application/javascript" src="../darkToggler.js"></script>
+<script type="application/javascript" src="{{ .Site.BaseURL }}darkToggler.js"></script>
 
 <link rel="canonical" href="{{ .Permalink }}" >
 <link rel="sitemap" href="{{ "sitemap.xml" | absURL }}" type="application/xml" />
diff --git a/static/darkToggler.js b/static/darkToggler.js
@@ -1,21 +1,30 @@
 (function() {
   window.onload = function() {
-    console.log("Nice! You have the privilege of toggling the dark mode :D");
-    console.log("Just press the 🌞 or 🌛 logo on the top of page!");
     const toggler = document.getElementById("dark-toggler");
     const mainWrapper = document.getElementById("main-theme");
+    const currentTheme = localStorage.getItem("theme");
 
     if (toggler && mainWrapper) {
       toggler.className = "header__menu__list__toggler";
       toggler.onclick = function() {
         if (mainWrapper.className === "theme-light") {
           mainWrapper.className = "theme-dark";
+          localStorage.setItem("theme", "dark");
           toggler.innerText = "🌛";
         } else if (mainWrapper.className === "theme-dark") {
           mainWrapper.className = "theme-light";
+          localStorage.setItem("theme", "light");
           toggler.innerText = "🌞";
         }
       };
     }
+
+    if (currentTheme && currentTheme === "light") {
+      mainWrapper.className = "theme-light";
+      toggler.innerText = "🌞";
+    }
+
+    console.log("Nice! You have the privilege of toggling the dark mode :D");
+    console.log("Just press the 🌞 or 🌛 logo on the top of page!");
   }
 })() 
\ No newline at end of file