Skip to content

Commit 878d78e

Browse files
Feature: Generalised Dark Mode into General Theme (#4348)
* Refactored the dark mode into general theme, Automatic reload after theme selection, Updated README.md for theme customisation * Grammatical Revisions
1 parent 920c018 commit 878d78e

File tree

13 files changed

+633
-399
lines changed

13 files changed

+633
-399
lines changed

css/activities.css

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,7 @@
1616
outline: none;
1717
}
1818

19-
body:not(.dark-mode) #helpfulSearch,
20-
body:not(.dark-mode) .ui-autocomplete {
21-
background-color: #fff !important;
22-
color: #000 !important;
23-
}
24-
25-
body:not(.dark-mode) .ui-autocomplete li:hover {
26-
background-color: #ddd !important;
27-
}
2819

29-
body:not(.dark-mode) #helpfulSearchDiv {
30-
background-color: #f9f9f9 !important;
31-
}
3220

3321
.modal {
3422
display: none;

css/darkmode.css

Lines changed: 0 additions & 81 deletions
This file was deleted.

css/themes.css

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/* Dark Mode */
2+
3+
.dark .blue {
4+
background-color: #022363 !important;
5+
}
6+
7+
.dark .blue.darken-1 {
8+
background-color: #01143b !important;
9+
}
10+
11+
.dark #floatingWindows > .windowFrame {
12+
border: 2px solid #000000;
13+
background-color: #454545;
14+
}
15+
16+
.dark .wfbtItem {
17+
background-color: #225a91;
18+
}
19+
20+
.dark #floatingWindows > .windowFrame > .wfTopBar .wftTitle {
21+
color: #e8e8e8;
22+
}
23+
24+
.dark .popupMsg {
25+
background-color: #084e86;
26+
color: #e8e8e8;
27+
}
28+
29+
.dark #printText {
30+
border-color: #000000;
31+
}
32+
33+
.dark #loading-image-container {
34+
background: #1a1a1a !important;
35+
background-color: #1a1a1a !important;
36+
}
37+
38+
.dark #loadingText {
39+
color: white !important;
40+
}
41+
42+
.dark .dropdown-content li > a {
43+
background-color: #1c1c1c;
44+
color: #3fe0d1;
45+
}
46+
47+
.dark .dropdown-content li > a:hover {
48+
color: #252525;
49+
}
50+
51+
.dark .dropdown-content {
52+
background-color: #1c1c1c;
53+
}
54+
55+
.dark .language-link {
56+
color: #fff;
57+
}
58+
59+
.dark .modal-content {
60+
background-color: #1c1c1c;
61+
color: #fff;
62+
}
63+
64+
.dark #submitLilypond {
65+
background-color: rgb(0, 102, 255);
66+
}
67+
68+
.dark #search,
69+
#helpfulSearch,
70+
.ui-autocomplete {
71+
background-color: #1c1c1c;
72+
color: #fff;
73+
}
74+
75+
.dark .ui-autocomplete li:hover {
76+
background-color: #225a91;
77+
}
78+
79+
.dark #helpfulSearchDiv {
80+
background-color: transparent;
81+
}
82+
83+
.dark #crossButton {
84+
color: #fff;
85+
}
86+
87+
88+
/* Your Custom Theme can go here if you don't want to modify the existing dark mode */

index.html

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070

7171
<link type="text/css" href="fonts/material-icons.css" rel="stylesheet"/>
7272
<link rel="stylesheet" href="lib/materialize-iso.css" />
73-
<link rel="stylesheet" href="css/darkmode.css" />
73+
<link rel="stylesheet" href="css/themes.css" />
7474

7575
<script src="lib/easeljs.min.js" defer></script>
7676

@@ -776,13 +776,13 @@
776776
>
777777
</li>
778778
<li>
779-
<a
780-
id="darkModeIcon"
781-
class="tooltipped"
782-
data-position="bottom"
783-
><i class="material-icons md-48"
784-
>brightness_4</i
785-
></a>
779+
<a
780+
id="themeSelectIcon"
781+
class="tooltipped dropdown-trigger"
782+
data-position="left"
783+
data-activates="themedropdown"
784+
><i class="material-icons md-48">brightness_4</i></a
785+
>
786786
</li>
787787
<li>
788788
<a
@@ -920,6 +920,12 @@
920920
<li><a id="he"></a></li>
921921
<li><a id="ur"></a></li>
922922
</ul>
923+
924+
<ul id="themedropdown" class="dropdown-content">
925+
<li><a id="light"></a></li>
926+
<li><a id="dark"></a></li>
927+
</ul>
928+
923929
<div id="modal-container" style="display: none;z-index: 999;">
924930
<ul id="newdropdown" class="dropdown-content" style="padding: 24px;">
925931
</ul>

js/activity.js

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
getMacroExpansion, getOctaveRatio, getTemperament, GOHOMEBUTTON,
2727
GOHOMEFADEDBUTTON, GRAND, HelpWidget, HIDEBLOCKSFADEDBUTTON,
2828
hideDOMLabel, initBasicProtoBlocks, initPalettes,
29-
INLINECOLLAPSIBLES, jQuery, JSEditor, LanguageBox, Logo, MSGBLOCK,
29+
INLINECOLLAPSIBLES, jQuery, JSEditor, LanguageBox, ThemeBox, Logo, MSGBLOCK,
3030
NANERRORMSG, NOACTIONERRORMSG, NOBOXERRORMSG, NOINPUTERRORMSG,
3131
NOMICERRORMSG, NOSQRTERRORMSG, NOSTRINGERRORMSG, PALETTEFILLCOLORS,
3232
PALETTESTROKECOLORS, PALETTEHIGHLIGHTCOLORS, HIGHLIGHTSTROKECOLORS,
@@ -85,6 +85,7 @@ let MYDEFINES = [
8585
"activity/turtle-singer",
8686
"activity/turtle-painter",
8787
"activity/languagebox",
88+
"activity/themebox",
8889
"activity/basicblocks",
8990
"activity/blockfactory",
9091
"activity/piemenus",
@@ -272,15 +273,17 @@ class Activity {
272273
//Flag to check if any other input box is active or not
273274
this.isInputON = false;
274275

275-
// If the theme is set to "darkMode", enable dark mode else diable
276+
this.themes = ["light", "dark"];
276277
try {
277-
if (this.storage.myThemeName === "darkMode") {
278-
body.classList.add("dark-mode");
279-
} else {
280-
body.classList.remove("dark-mode");
278+
for (let i = 0; i < this.themes.length; i++) {
279+
if (this.themes[i] === this.storage.themePreference) {
280+
body.classList.add(this.themes[i]);
281+
} else {
282+
body.classList.remove(this.themes[i]);
283+
}
281284
}
282285
} catch (e) {
283-
console.error("Error accessing myThemeName storage:", e);
286+
console.error("Error accessing themePreference storage:", e);
284287
}
285288

286289
this.beginnerMode = true;
@@ -385,6 +388,7 @@ class Activity {
385388
this.logo = null;
386389
this.pasteBox = null;
387390
this.languageBox = null;
391+
this.themeBox = null;
388392
this.planet = null;
389393
window.converter = null;
390394
this.buttonsVisible = true;
@@ -6678,28 +6682,7 @@ class Activity {
66786682

66796683
this._createErrorContainers();
66806684

6681-
// Function to toggle theme mode
6682-
this.toggleThemeMode = () => {
6683-
if (this.storage.myThemeName === "darkMode") {
6684-
delete this.storage.myThemeName;
6685-
localStorage.setItem("darkMode", "disabled");
6686-
} else {
6687-
this.storage.myThemeName = "darkMode";
6688-
localStorage.setItem("darkMode", "enabled");
6689-
}
6690-
const planetIframe = document.getElementById("planet-iframe");
6691-
if (planetIframe) {
6692-
planetIframe.contentWindow.postMessage(
6693-
{ darkMode: localStorage.getItem("darkMode") },
6694-
"*"
6695-
);
6696-
}
6697-
try {
6698-
window.location.reload();
6699-
} catch (e) {
6700-
console.error("Error reloading the window:", e);
6701-
}
6702-
};
6685+
67036686

67046687
/* Z-Order (top to bottom):
67056688
* menus
@@ -6727,6 +6710,7 @@ class Activity {
67276710

67286711
this.pasteBox = new PasteBox(this);
67296712
this.languageBox = new LanguageBox(this);
6713+
this.themeBox = new ThemeBox(this);
67306714

67316715
// Show help on startup if first-time user.
67326716
if (this.firstTimeUser) {
@@ -6768,7 +6752,7 @@ class Activity {
67686752
this.toolbar.renderModeSelectIcon(doSwitchMode, doRecordButton, doAnalytics, doOpenPlugin, deletePlugin, setScroller);
67696753
this.toolbar.renderRunSlowlyIcon(doSlowButton);
67706754
this.toolbar.renderRunStepIcon(doStepButton);
6771-
this.toolbar.renderDarkModeIcon(this.toggleThemeMode);
6755+
this.toolbar.renderThemeSelectIcon(this.themeBox, this.themes);
67726756
this.toolbar.renderMergeIcon(_doMergeLoad);
67736757
this.toolbar.renderRestoreIcon(restoreTrash);
67746758
if (_THIS_IS_MUSIC_BLOCKS_) {
@@ -7333,7 +7317,7 @@ class Activity {
73337317
saveLocally() {
73347318
try {
73357319
localStorage.setItem('beginnerMode', this.beginnerMode.toString());
7336-
localStorage.setItem('isDarkModeON', this.isDarkModeON.toString());
7320+
localStorage.setItem("themePreference", this.themePreference.toString());
73377321
} catch (e) {
73387322
// eslint-disable-next-line no-console
73397323
console.error('Error saving to localStorage:', e);

0 commit comments

Comments
 (0)