Skip to content

Commit c3fa8bd

Browse files
Dexusahmadileham
andcommitted
add initial dark mode (#30)
* add initial dark mode fixes #21 Co-authored-by: ahmadileham <96009848+ahmadileham@users.noreply.github.com> * darkmode --------- Co-authored-by: ahmadileham <96009848+ahmadileham@users.noreply.github.com>
1 parent 98d841a commit c3fa8bd

File tree

3 files changed

+293
-31
lines changed

3 files changed

+293
-31
lines changed

main/img/dark_mode.svg

Lines changed: 3 additions & 0 deletions
Loading

main/index.html

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,42 @@
4444
const svgPreProcessor = require('@deepnest/svg-preprocessor');
4545

4646
ready(async function () {
47+
// check for dark mode preference
48+
const darkMode = localStorage.getItem('darkMode') === 'true';
49+
if (darkMode) {
50+
document.body.classList.add('dark-mode');
51+
}
52+
4753
// main navigation
4854
var tabs = document.querySelectorAll('#sidenav li');
4955

5056
Array.from(tabs).forEach(tab => {
5157
tab.addEventListener('click', function (e) {
52-
if (this.className == 'active' || this.className == 'disabled') {
53-
return false;
54-
}
58+
// darkmode handler
59+
if(this.id == 'darkmode_tab'){
60+
document.body.classList.toggle('dark-mode');
61+
localStorage.setItem('darkMode', document.body.classList.contains('dark-mode'));
62+
} else {
63+
64+
if (this.className == 'active' || this.className == 'disabled') {
65+
return false;
66+
}
5567

56-
var activetab = document.querySelector('#sidenav li.active');
57-
activetab.className = '';
68+
var activetab = document.querySelector('#sidenav li.active');
69+
activetab.className = '';
5870

59-
var activepage = document.querySelector('.page.active');
60-
activepage.className = 'page';
71+
var activepage = document.querySelector('.page.active');
72+
activepage.className = 'page';
6173

62-
this.className = 'active';
63-
tabpage = document.querySelector('#' + this.dataset.page);
64-
tabpage.className = 'page active';
74+
this.className = 'active';
75+
tabpage = document.querySelector('#' + this.dataset.page);
76+
tabpage.className = 'page active';
6577

66-
if (tabpage.getAttribute('id') == 'home') {
67-
resize();
78+
if (tabpage.getAttribute('id') == 'home') {
79+
resize();
80+
}
81+
return false;
6882
}
69-
return false;
7083
});
7184
});
7285

@@ -1718,6 +1731,7 @@
17181731
<li id="config_tab" data-page="config"></li>
17191732
<!--<li id="account_tab" data-page="account"></li>-->
17201733
<li id="info_tab" data-page="info"></li>
1734+
<li id="darkmode_tab"></li>
17211735
</ul>
17221736

17231737
<div id="home" class="page active">

0 commit comments

Comments
 (0)