Skip to content

Commit 70bec3c

Browse files
authored
Dark mode (#4244)
* highlights fix * Dark Mode * css file added * css toogle * linked to html * fix 1 * update 2 * update 3 * suggested changes are updated * added README file * space * no boolean * platformColor * platform2 * highlight fix
1 parent 7051321 commit 70bec3c

File tree

11 files changed

+518
-171
lines changed

11 files changed

+518
-171
lines changed

css/darkmode.css

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
.dark-mode .blue {
2+
background-color: #022363 !important;
3+
}
4+
5+
.dark-mode .blue.darken-1 {
6+
background-color: #01143b !important;
7+
}
8+
9+
.dark-mode #floatingWindows > .windowFrame {
10+
border: 2px solid #000000;
11+
background-color: #454545;
12+
}
13+
14+
.dark-mode .wfbtItem {
15+
background-color: #225a91;
16+
}
17+
18+
.dark-mode #floatingWindows > .windowFrame > .wfTopBar .wftTitle {
19+
color: #e8e8e8;
20+
}
21+
22+
.dark-mode .popupMsg {
23+
background-color: #084e86;
24+
color: #e8e8e8;
25+
}
26+
27+
.dark-mode #printText {
28+
border-color: #000000;
29+
}
30+
31+
.dark-mode #loading-image-container {
32+
background: #1a1a1a !important;
33+
background-color: #1a1a1a !important;
34+
}
35+
36+
.dark-mode #loadingText {
37+
color: white !important;
38+
}
39+
40+
.dark-mode .dropdown-content li > a{
41+
background-color: #1c1c1c;
42+
color: #3fe0d1;
43+
}
44+
45+
.dark-mode .dropdown-content li > a:hover {
46+
color: #252525
47+
}
48+
49+
.dark-mode .dropdown-content{
50+
background-color: #1c1c1c;
51+
}
52+
53+

index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +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" />
7374

7475
<script src="lib/easeljs.min.js" defer></script>
7576

@@ -767,6 +768,15 @@
767768
></a
768769
>
769770
</li>
771+
<li>
772+
<a
773+
id="darkModeIcon"
774+
class="tooltipped"
775+
data-position="bottom"
776+
><i class="material-icons md-48"
777+
>brightness_4</i
778+
></a>
779+
</li>
770780
<li>
771781
<a
772782
id="mergeWithCurrentIcon"

js/activity.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,17 @@ class Activity {
272272
//Flag to check if any other input box is active or not
273273
this.isInputON = false;
274274

275+
// If the theme is set to "darkMode", enable dark mode else diable
276+
try {
277+
if (this.storage.myThemeName === "darkMode") {
278+
body.classList.add("dark-mode");
279+
} else {
280+
body.classList.remove("dark-mode");
281+
}
282+
} catch (e) {
283+
console.error("Error accessing myThemeName storage:", e);
284+
}
285+
275286
this.beginnerMode = true;
276287
try {
277288
if (this.storage.beginnerMode === undefined) {
@@ -1054,31 +1065,31 @@ class Activity {
10541065
modal.style.transform = "translate(-50%, -50%)";
10551066
modal.style.width = "400px";
10561067
modal.style.padding = "24px";
1057-
modal.style.backgroundColor = "#fff";
1068+
modal.style.backgroundColor = platformColor.dialogueBox;
10581069
modal.style.boxShadow = "0 4px 8px rgba(0, 0, 0, 0.2)";
10591070
modal.style.borderRadius = "8px";
10601071
modal.style.zIndex = "10000";
10611072
modal.style.textAlign = "left";
10621073
const title = document.createElement("h2");
10631074
title.textContent = "Clear Workspace";
1064-
title.style.color = "#0066FF";
1075+
title.style.color = platformColor.blueButton;
10651076
title.style.fontSize = "24px";
10661077
title.style.margin = "0 0 16px 0";
10671078
modal.appendChild(title);
10681079
const message = document.createElement("p");
1069-
message.textContent = "Are you sure you want to clear the workspace?";
1070-
message.style.color = "#666666";
1080+
message.textContent = _("Are you sure you want to clear the workspace?");
1081+
message.style.color = platformColor.textColor;
10711082
message.style.fontSize = "16px";
10721083
message.style.marginBottom = "24px";
10731084
modal.appendChild(message);
10741085
// Add buttons
10751086
const buttonContainer = document.createElement("div");
10761087
buttonContainer.style.display = "flex";
10771088
buttonContainer.style.justifyContent = "flex-start";
1078-
1089+
10791090
const confirmBtn = document.createElement("button");
10801091
confirmBtn.textContent = "Confirm";
1081-
confirmBtn.style.backgroundColor = "#2196F3";
1092+
confirmBtn.style.backgroundColor = platformColor.blueButton;
10821093
confirmBtn.style.color = "white";
10831094
confirmBtn.style.border = "none";
10841095
confirmBtn.style.borderRadius = "4px";
@@ -1670,7 +1681,7 @@ class Activity {
16701681
if (this.blockscale > 0) {
16711682
this.resizeDebounce = true;
16721683
this.blockscale -= 1;
1673-
this.clearCache();
1684+
this.clearCache();
16741685
await this.blocks.setBlockScale(BLOCKSCALES[this.blockscale]);
16751686
this.blocks.checkBounds();
16761687
this.refreshCanvas();
@@ -6561,6 +6572,21 @@ class Activity {
65616572

65626573
this._createErrorContainers();
65636574

6575+
// Function to toggle theme mode
6576+
this.toggleThemeMode = () => {
6577+
if (this.storage.myThemeName === "darkMode") {
6578+
// If currently in dark mode, remove the theme
6579+
delete this.storage.myThemeName;
6580+
} else {
6581+
this.storage.myThemeName = "darkMode";
6582+
}
6583+
try {
6584+
window.location.reload();
6585+
} catch (e) {
6586+
console.error("Error reloading the window:", e);
6587+
}
6588+
};
6589+
65646590
/* Z-Order (top to bottom):
65656591
* menus
65666592
* palettes
@@ -6627,6 +6653,7 @@ class Activity {
66276653
this.toolbar.renderModeSelectIcon(doSwitchMode, doRecordButton, doAnalytics, doOpenPlugin, deletePlugin, setScroller);
66286654
this.toolbar.renderRunSlowlyIcon(doSlowButton);
66296655
this.toolbar.renderRunStepIcon(doStepButton);
6656+
this.toolbar.renderDarkModeIcon(this.toggleThemeMode);
66306657
this.toolbar.renderMergeIcon(_doMergeLoad);
66316658
this.toolbar.renderRestoreIcon(restoreTrash);
66326659
if (_THIS_IS_MUSIC_BLOCKS_) {
@@ -7190,6 +7217,7 @@ class Activity {
71907217
saveLocally() {
71917218
try {
71927219
localStorage.setItem('beginnerMode', this.beginnerMode.toString());
7220+
localStorage.setItem('isDarkModeON', this.isDarkModeON.toString());
71937221
} catch (e) {
71947222
console.error('Error saving to localStorage:', e);
71957223
}

js/palette.js

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,13 @@ class Palettes {
130130
td.width = 1.5 * this.cellSize;
131131
td.height = 1.5 * this.cellSize;
132132
td.style.position = "relative";
133+
td.style.backgroundColor = platformColor.paletteBackground;
133134
td.appendChild(
134135
makePaletteIcons(
135136
PALETTEICONS[MULTIPALETTEICONS[i]]
136-
.replace("background_fill_color", platformColor.selectorBackground)
137-
.replace(/stroke_color/g, platformColor.ruleColor)
138-
.replace(/fill_color/g, platformColor.background),
137+
.replace("background_fill_color", platformColor.paletteLabelBackground)
138+
.replace(/stroke_color/g, platformColor.strokeColor)
139+
.replace(/fill_color/g, platformColor.fillColor),
139140
1.5 * this.cellSize,
140141
1.5 * this.cellSize
141142
)
@@ -146,7 +147,7 @@ class Palettes {
146147
cover.style.top = "0";
147148
cover.style.width = "100%";
148149
cover.style.height = "1px";
149-
cover.style.background = platformColor.selectorBackground;
150+
cover.style.background = platformColor.paletteLabelBackground;
150151
td.appendChild(cover);
151152
td.onmouseover = () => {
152153
this.showSelection(i, tr);
@@ -161,23 +162,23 @@ class Palettes {
161162
if (j === i) {
162163
img = makePaletteIcons(
163164
PALETTEICONS[MULTIPALETTEICONS[j]]
164-
.replace("background_fill_color", platformColor.selectorSelected)
165-
.replace(/stroke_color/g, platformColor.ruleColor)
166-
.replace(/fill_color/g, platformColor.background),
165+
.replace("background_fill_color", platformColor.paletteLabelSelected)
166+
.replace(/stroke_color/g, platformColor.strokeColor)
167+
.replace(/fill_color/g, platformColor.fillColor),
167168
this.cellSize,
168169
this.cellSize
169170
);
170-
tr.children[j].children[1].style.background = platformColor.selectorSelected;
171+
tr.children[j].children[1].style.background = platformColor.paletteLabelSelected;
171172
} else {
172173
img = makePaletteIcons(
173174
PALETTEICONS[MULTIPALETTEICONS[j]]
174-
.replace("background_fill_color", platformColor.selectorBackground)
175-
.replace(/stroke_color/g, platformColor.ruleColor)
176-
.replace(/fill_color/g, platformColor.background),
175+
.replace("background_fill_color", platformColor.paletteLabelBackground)
176+
.replace(/stroke_color/g, platformColor.strokeColor)
177+
.replace(/fill_color/g, platformColor.fillColor),
177178
this.cellSize,
178179
this.cellSize
179180
);
180-
tr.children[j].children[1].style.background = platformColor.selectorBackground;
181+
tr.children[j].children[1].style.background = platformColor.paletteLabelBackground;
181182
}
182183
tr.children[j].children[0].src = img.src;
183184
}
@@ -283,7 +284,7 @@ class Palettes {
283284
);
284285
}
285286
}
286-
287+
287288
makeSearchButton(name, icon, listBody) {
288289
const row = listBody.insertRow(-1);
289290
const img = row.insertCell(-1);
@@ -302,6 +303,7 @@ class Palettes {
302303
row.style.flexDirection = "row";
303304
row.style.alignItems = "center";
304305
row.style.width = "126px";
306+
row.style.backgroundColor = platformColor.paletteBackground;
305307

306308
this._loadPaletteButtonHandler(name, row);
307309
}
@@ -323,6 +325,13 @@ class Palettes {
323325
row.style.flexDirection = "row";
324326
row.style.alignItems = "center";
325327
row.style.width = "126px";
328+
row.style.backgroundColor = platformColor.paletteBackground;
329+
row.addEventListener('mouseover', () => {
330+
row.style.backgroundColor = platformColor.hoverColor;
331+
});
332+
row.addEventListener('mouseout', () => {
333+
row.style.backgroundColor = platformColor.paletteBackground;
334+
});
326335

327336
this._loadPaletteButtonHandler(name, row);
328337
}
@@ -426,7 +435,7 @@ class Palettes {
426435
'px"bgcolor="white"><thead><tr><td style= "width:28px"></tr></thead><tbody></tbody></table></div>';
427436
element.childNodes[0].style.border = `1px solid ${platformColor.selectorSelected}`;
428437
document.body.appendChild(element);
429-
438+
430439
} catch (e) {
431440
console.error('Error clearing palettes:', e);
432441
}
@@ -457,9 +466,9 @@ class Palettes {
457466
timeout = setTimeout(() => this.showPalette(name), 400);
458467
}
459468
};
460-
469+
461470
row.onmouseout = () => clearTimeout(timeout);
462-
471+
463472
// eslint-disable-next-line no-unused-vars
464473
row.onclick = (event) => {
465474
if (name == "search") {
@@ -881,7 +890,7 @@ class Palette {
881890
if (createHeader) {
882891
let header = this.menuContainer.children[0];
883892
header = header.insertRow();
884-
header.style.background = platformColor.selectorSelected;
893+
header.style.backgroundColor = platformColor.paletteLabelBackground;
885894
header.innerHTML =
886895
'<td style ="width: 100%; height: 42px; box-sizing: border-box; display: flex; flex-direction: row; align-items: center; justify-content: space-between;"></td>';
887896
header = header.children[0];
@@ -900,7 +909,7 @@ class Palette {
900909
const label = document.createElement("span");
901910
label.textContent = toTitleCase(_(this.name));
902911
label.style.fontWeight = "bold";
903-
label.style.color = platformColor.paletteBackground;
912+
label.style.color = platformColor.textColor;
904913
header.appendChild(label);
905914

906915
const closeDownImg = document.createElement("span");

js/planetInterface.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ class PlanetInterface {
307307
*/
308308
this.init = async () => {
309309
this.iframe = document.getElementById("planet-iframe");
310+
this.iframe.style.backgroundColor = platformColor.background;
310311
try {
311312
await this.iframe.contentWindow.makePlanet(
312313
_THIS_IS_MUSIC_BLOCKS_,

js/toolbar.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class Toolbar {
6767
["delPluginIcon", _("Delete plugin")],
6868
["enableHorizScrollIcon", _("Enable horizontal scrolling")],
6969
["disableHorizScrollIcon", _("Disable horizontal scrolling")],
70+
["darkModeIcon", _("Change theme")],
7071
["mergeWithCurrentIcon", _("Merge with current project")],
7172
["chooseKeyIcon", _("Set Pitch Preview")],
7273
["toggleJavaScriptIcon", _("JavaScript Editor")],
@@ -128,6 +129,7 @@ class Toolbar {
128129
_("Delete plugin"),
129130
_("Enable horizontal scrolling"),
130131
_("Disable horizontal scrolling"),
132+
_("Change theme"),
131133
_("Merge with current project"),
132134
_("Set Pitch Preview"),
133135
_("JavaScript Editor"),
@@ -193,6 +195,7 @@ class Toolbar {
193195
["delPluginIcon", _("Delete plugin")],
194196
["enableHorizScrollIcon", _("Enable horizontal scrolling")],
195197
["disableHorizScrollIcon", _("Disable horizontal scrolling")],
198+
["darkModeIcon", _("Change theme")],
196199
["mergeWithCurrentIcon", _("Merge with current project")],
197200
["toggleJavaScriptIcon", _("JavaScript Editor")],
198201
["restoreIcon", _("Restore")],
@@ -249,6 +252,7 @@ class Toolbar {
249252
_("Delete plugin"),
250253
_("Enable horizontal scrolling"),
251254
_("Disable horizontal scrolling"),
255+
_("Change theme"),
252256
_("Merge with current project"),
253257
_("JavaScript Editor"),
254258
_("Restore"),
@@ -433,7 +437,7 @@ class Toolbar {
433437

434438
/**
435439
* Renders the load icon with the provided onclick handler.
436-
*
440+
*
437441
* @public
438442
* @param {Function} onclick - The onclick handler for the load icon.
439443
* @returns {void}
@@ -446,6 +450,14 @@ class Toolbar {
446450
};
447451
}
448452

453+
renderDarkModeIcon(onclick) {
454+
const darkModeIcon = docById("darkModeIcon");
455+
456+
darkModeIcon.onclick = () => {
457+
onclick();
458+
}
459+
}
460+
449461
/**
450462
* Renders the wrap icon.
451463
*
@@ -1085,7 +1097,7 @@ function renderNewProjectConfirmation() {
10851097
const confirmationButton = document.createElement("a");
10861098
confirmationButton.id = "new-project";
10871099
confirmationButton.style.display = "inline-block";
1088-
confirmationButton.style.backgroundColor = "#2196F3";
1100+
confirmationButton.style.backgroundColor = platformColor.blueButton;
10891101
confirmationButton.style.color = "white";
10901102
confirmationButton.style.textDecoration = "none";
10911103
confirmationButton.style.borderRadius = "4px";

0 commit comments

Comments
 (0)