mirror of
https://github.com/minio/docs.git
synced 2025-07-30 07:03:26 +03:00
Light/dark mode: avoid flickering on page reload (#995)
**Current behaviour:** https://github.com/minio/docs/assets/13393018/1c8b5762-9ee5-45ec-9e44-88f99c1750dd **Fix:** https://github.com/minio/docs/assets/13393018/658f7858-d793-40ca-87de-8f519a12dffa
This commit is contained in:
@ -74,17 +74,6 @@ window.addEventListener("DOMContentLoaded", (event) => {
|
||||
// --------------------------------------------------
|
||||
(function () {
|
||||
const readModeEl = document.getElementById("read-mode-toggle");
|
||||
const headerEl = document.querySelector(".header");
|
||||
|
||||
// Check if the read mode in enabled in user's local storage
|
||||
if (readModeLs === "true") {
|
||||
document.documentElement.classList.add("read-mode");
|
||||
readModeEl.classList.add("active");
|
||||
}
|
||||
|
||||
// Make header visible after the page is loaded and read-mode is decided.
|
||||
// This is to prevent the flickering of the header on page load.
|
||||
headerEl.classList.remove("inactive");
|
||||
|
||||
// Toggle read mode on icon click
|
||||
readModeEl.addEventListener("click", (event) => {
|
||||
@ -136,13 +125,6 @@ window.addEventListener("DOMContentLoaded", (event) => {
|
||||
// --------------------------------------------------
|
||||
(function () {
|
||||
const darkModeEl = document.getElementById("dark-mode-toggle");
|
||||
var darkModeLs = localStorage.getItem("dark-mode");
|
||||
|
||||
// Check if the dark mode in enabled in user's local storage
|
||||
if (darkModeLs === "true") {
|
||||
document.documentElement.classList.add("dark-mode");
|
||||
darkModeEl.classList.add("active");
|
||||
}
|
||||
|
||||
darkModeEl.addEventListener("click", (event) => {
|
||||
document.documentElement.classList.toggle("dark-mode");
|
||||
|
@ -8,10 +8,6 @@
|
||||
& > .container {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
&.inactive {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.header__top {
|
||||
|
20
source/_templates/custom-scripts.html
Normal file
20
source/_templates/custom-scripts.html
Normal file
@ -0,0 +1,20 @@
|
||||
<script>
|
||||
// Dark mode and read mode detection
|
||||
|
||||
// Dark mode
|
||||
var isDarkMode = localStorage.getItem("dark-mode");
|
||||
var dmToggleBtn = document.getElementById("dark-mode-toggle");
|
||||
if (isDarkMode === "true") {
|
||||
document.documentElement.classList.add("dark-mode");
|
||||
dmToggleBtn.classList.add("active");
|
||||
}
|
||||
|
||||
// Read mode
|
||||
var isReadMode = localStorage.getItem("read-mode");
|
||||
var rmToggleBtn = document.getElementById("read-mode-toggle");
|
||||
|
||||
if (isReadMode === "true") {
|
||||
document.documentElement.classList.add("read-mode");
|
||||
rmToggleBtn.classList.add("active");
|
||||
}
|
||||
</script>
|
@ -93,4 +93,5 @@
|
||||
|
||||
{%- block footer %}
|
||||
{%- include "cookie.html" %}
|
||||
{%- include "custom-scripts.html" %}
|
||||
{%- endblock %}
|
Reference in New Issue
Block a user