Skip to content
This repository has been archived by the owner on Jun 23, 2021. It is now read-only.

Dark Mode for subpages #76

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions _sass/page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ body {
.page h2 {
text-align: left !important;
font-weight: 800 !important;
color: $text_color;
color: inherit;
font-size: $fontsize_h2;
margin-bottom: 0.5em;
}
Expand All @@ -70,7 +70,7 @@ body {
}

.page p {
color: $text_color;
color: inherit;
font-weight: 500;
}

Expand Down
29 changes: 24 additions & 5 deletions assets/js/darkmode.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,44 @@ let toogleStatus = document.getElementById('check-mode');
let bodyElement = document.getElementsByTagName('body')[0];
let navLogo = document.getElementsByClassName('nav-logo')[0];
let cards = document.getElementsByClassName('card');
let container = document.getElementsByClassName('page');
let footer = document.getElementsByClassName('footer');

console.log(imode);
if(imode == "true"){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(imode == "true"){
if (imode === null) {
localStorage.setItem("isDark", false);
}
if(imode == "true"){

toogleStatus.checked = true;
darkmode()
darkmode();
}

function darkmode(){
if(toogleStatus.checked){
bodyElement.className += " " + "darkmode";
navLogo.className += " " + "darkmode";
for(let i = 0; i < cards.length; i++){
cards[i].className += " " + "alt-background";
if(cards){
for(let i = 0; i < cards.length; i++){
cards[i].className += " " + "alt-background";
}
}
if(container[0]){
container[0].className += " " + "darkmode";
}
if(footer[0]){
footer[0].className += " " + "darkmode";
}
localStorage.setItem("isDark", true);
}else{
bodyElement.classList.remove('darkmode');
navLogo.classList.remove('darkmode');
for(let i = 0; i < cards.length; i++){
cards[i].classList.remove('alt-background');
if(cards){
for(let i = 0; i < cards.length; i++){
cards[i].classList.remove('alt-background');
}
}
if(container[0]){
container[0].classList.remove("darkmode");
}
if(footer[0]){
footer[0].classList.remove("darkmode");
}
localStorage.setItem("isDark", false);
}
Expand Down