Skip to content

Commit 61989c2

Browse files
committed
theme changing fixes
1 parent 84ad79c commit 61989c2

File tree

4 files changed

+57
-26
lines changed

4 files changed

+57
-26
lines changed

static/standardUI/js/changeTheme.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
var root = document.querySelector(":root");
22
var changeTheme = document.querySelector(".changeTheme");
33

4-
var theme = localStorage.setItem("theme", "dark");
4+
var theme;
55

6-
if (localStorage.getItem(theme) === "dark") {
6+
if (localStorage.getItem("theme") === "dark") {
77
toDark();
8-
} else if (localStorage.getItem(theme) === "light") {
8+
} else if (localStorage.getItem("theme") === "light") {
99
toLight();
10+
} else if (localStorage.getItem("theme") === null) {
11+
toDark();
1012
}
1113

1214
function toLight() {
13-
localStorage.setItem(theme, "light");
15+
localStorage.setItem("theme", "light");
1416
root.style.setProperty("--themePrimary", "#000");
1517
root.style.setProperty("--themeSecondary", "#fff");
1618
root.style.setProperty("--themeHelper", "#303030");
17-
changeTheme.innerHTML = '<i class="ti ti-moon"></i>';
19+
changeTheme.innerHTML = '<i class="ti ti-sun"></i>';
1820
changeTheme.setAttribute("onclick", "javascript: toDark();");
1921
}
2022

2123
function toDark() {
22-
localStorage.setItem(theme, "dark");
24+
localStorage.setItem("theme", "dark");
2325
root.style.setProperty("--themePrimary", "#fff");
2426
root.style.setProperty("--themeSecondary", "#000");
2527
root.style.setProperty("--themeHelper", "#C6C6C6");
26-
changeTheme.innerHTML = '<i class="ti ti-sun"></i>';
28+
changeTheme.innerHTML = '<i class="ti ti-moon"></i>';
2729
changeTheme.setAttribute("onclick", "javascript: toLight();");
2830
}

static/tailwindUI/js/changeTheme.js

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,59 @@
11
var body = document.querySelector("#body");
22
var changeTheme = document.querySelector(".changeTheme");
33

4-
var theme = localStorage.setItem("theme", "dark");
4+
var theme;
55

6-
if (localStorage.getItem(theme) === "dark") {
6+
if (localStorage.getItem("theme") === "dark") {
77
toDark();
8-
} else if (localStorage.getItem(theme) === "light") {
8+
} else if (localStorage.getItem("theme") === "light") {
99
toLight();
10+
} else if (localStorage.getItem("theme") === null) {
11+
toDark();
1012
}
11-
13+
/**
14+
* Changes the theme of the website to light mode.
15+
* @function
16+
*/
1217
function toLight() {
18+
"use strict";
19+
20+
// Set the theme in local storage
1321
localStorage.setItem("theme", "light");
14-
body.className =
15-
"text-neutral-100 bg-neutral-900 selection:bg-neutral-800 selection:text-rose-500";
16-
changeTheme.innerHTML = '<i class="ti ti-moon"></i>';
17-
changeTheme.setAttribute("onclick", "javascript: toDark();");
22+
23+
// Update the CSS class of the body element
24+
document.body.className =
25+
"text-neutral-900 bg-neutral-100 selection:bg-neutral-800 selection:text-rose-500";
26+
27+
// Update the HTML content of the button
28+
document.querySelector(".changeTheme").innerHTML =
29+
'<i class="ti ti-sun"></i>';
30+
31+
// Update the onclick event of the button
32+
document
33+
.querySelector(".changeTheme")
34+
.setAttribute("onclick", "javascript: toDark();");
1835
}
1936

37+
/**
38+
* Changes the theme of the website to dark mode.
39+
* @function
40+
*/
2041
function toDark() {
42+
"use strict";
43+
44+
// Set the theme in local storage
2145
localStorage.setItem("theme", "dark");
22-
body.className =
23-
"text-neutral-900 bg-neutral-100 selection:bg-neutral-200 selection:text-rose-500";
24-
changeTheme.innerHTML = '<i class="ti ti-sun"></i>';
25-
changeTheme.setAttribute("onclick", "javascript: toLight();");
46+
47+
// Update the CSS class of the body element
48+
document.body.className =
49+
"text-neutral-100 bg-neutral-900 selection:bg-neutral-800 selection:text-rose-500";
50+
51+
// Update the HTML content of the button
52+
document.querySelector(".changeTheme").innerHTML =
53+
'<i class="ti ti-moon"></i>';
54+
55+
// Update the onclick event of the button
56+
document
57+
.querySelector(".changeTheme")
58+
.setAttribute("onclick", "javascript: toLight();");
2659
}

templates/standardUI/changeTheme.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
href="{{ url_for('static', filename='css/changeTheme.css') }}"
44
/>
55
<section class="changeThemeContainer">
6-
<button class="changeTheme btn" onclick="toLight()">
7-
<i class="ti ti-sun"></i>
8-
</button>
6+
<button class="changeTheme btn" onclick="toDark()"></button>
97
<script src="{{ url_for('static', filename='js/changeTheme.js') }}"></script>
108
</section>

templates/tailwindUI/changeTheme.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<section>
22
<button
33
class="changeTheme absolute top-2 right-2 text-2xl hover:scale-125 duration-150"
4-
onclick="toLight()"
5-
>
6-
<i class="ti ti-sun"></i>
7-
</button>
4+
onclick="toDark()"
5+
></button>
86
<script src="{{ url_for('static', filename='js/changeTheme.js') }}"></script>
97
</section>

0 commit comments

Comments
 (0)