Skip to content

Commit 4720833

Browse files
committed
make desktop icons actually do things
1 parent d971ab5 commit 4720833

File tree

5 files changed

+49
-9
lines changed

5 files changed

+49
-9
lines changed

config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,26 @@ document.addEventListener("DOMContentLoaded", () => {
143143

144144
LEADERBOARD_ID = "leaderboard";
145145
MINESWEEPER_ID = "minesweeper";
146+
NOTEPAD_ID = "notepad";
146147

147148
const WINDOW_DEFAULTS = {
148149
[MINESWEEPER_ID]: {
149150
open: true,
150151
zIndex: WINDOW_Z_INDEX_STACK_START,
151152
},
152153
};
154+
155+
// Desktop Actions
156+
157+
const DESKTOP_CONFIG = {
158+
["desktop-open-minesweeper"]: {
159+
clickHandler: (event) => {
160+
setWindowVisibility(MINESWEEPER_ID, true);
161+
},
162+
},
163+
["desktop-open-notepad"]: {
164+
clickHandler: (event) => {
165+
setWindowVisibility(NOTEPAD_ID, true);
166+
},
167+
},
168+
};

desktop.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,24 @@ window.addEventListener("mouseup", () => {
3636
});
3737

3838
const didClickWindow = (element) => {
39+
return !!findParentOfClass(element, "draggable");
40+
};
41+
42+
const findParentOfClass = (element, classname) => {
3943
if (!element) {
40-
return false;
44+
return null;
4145
}
4246

4347
if (!element.parentElement) {
44-
return false;
48+
return null;
4549
}
4650

4751
const classList = element.classList;
48-
if (!classList.contains("draggable")) {
49-
return didClickWindow(element.parentElement);
52+
if (!classList.contains(classname)) {
53+
return findParentOfClass(element.parentElement, classname);
5054
}
5155

52-
return true;
56+
return element;
5357
};
5458

5559
const getSanePositions = () => {
@@ -129,12 +133,27 @@ window.addEventListener("mousedown", desktopClickHandler);
129133

130134
// Doubleclick
131135

132-
const desktopDoubleclickHandler = () => {};
136+
const desktopDoubleclickHandler = (event) => {
137+
const target = event.target;
138+
139+
if (!target) {
140+
return;
141+
}
142+
143+
const parent = findParentOfClass(target, "icon");
144+
const configItem = DESKTOP_CONFIG[parent.id];
145+
146+
if (!configItem) {
147+
return;
148+
}
149+
150+
configItem?.clickHandler();
151+
};
133152

134-
document.addEventListener("load", () => {
153+
window.addEventListener("load", () => {
135154
const desktopIcons = document.querySelectorAll(".desktop > .icon");
136155

137156
desktopIcons.forEach((icon) => {
138-
console.log(icon);
157+
icon.addEventListener("dblclick", desktopDoubleclickHandler);
139158
});
140159
});

draggables.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ window.addEventListener("load", () => {
111111
const setWindowVisibility = (id, visibility) => {
112112
const draggable = draggables.find((d) => d.id === id);
113113
draggable.open = visibility;
114+
promoteZIndex(draggable.id);
114115

115116
processDraggables();
116117
};

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ <h2>Mines:</h2>
185185
<div class="game-container notepad draggable" id="notepad">
186186
<div class="window-header">
187187
<div class="title-bar">
188-
<button>
188+
<button onclick="setWindowVisibility(NOTEPAD_ID, false)">
189189
<div class="minimize-button"></div>
190190
</button>
191191
<h1>Notepad - [untitled]</h1>

style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ table {
112112
user-select: none;
113113
}
114114

115+
.title-bar h1 {
116+
padding-top: 2px;
117+
}
118+
115119
.title-bar button {
116120
height: 100%;
117121
aspect-ratio: 1 / 1;

0 commit comments

Comments
 (0)