-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
80 lines (67 loc) · 2.52 KB
/
script.js
File metadata and controls
80 lines (67 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// This controls which app is on top.
let highestZIndex = 1;
// When the user clicks an icon, the app gets opened.
function openWindow(id) {
var win = document.getElementById(id);
var appIcon = document.getElementById('app-' + id);
if (win) {
win.style.display = 'flex';
win.style.zIndex = highestZIndex++;
if (appIcon) {
appIcon.classList.add('active-appbar-icon');
}
}
}
// When the user clicks the close button, the app gets closed.
function closeWindow(id) {
var win = document.getElementById(id);
var appIcon = document.getElementById('app-' + id);
if (win) {
win.style.display = 'none';
if (appIcon) {
appIcon.classList.remove('active-appbar-icon');
}
}
}
// Redirects to the SafeMode version.
window.addEventListener('keydown', function(event) {
if (event.ctrlKey && event.key === 's') {
event.preventDefault();
window.location.href = './safemode/index.html';
}
});
// This controls how the user can move the app window.
document.querySelectorAll('.window').forEach(windowElement => {
const header = windowElement.querySelector('.window-header');
let isDragging = false;
let offsetX, offsetY;
header.addEventListener('mousedown', (e) => {
isDragging = true;
offsetX = e.clientX - windowElement.offsetLeft;
offsetY = e.clientY - windowElement.offsetTop;
windowElement.style.zIndex = highestZIndex++;
});
document.addEventListener('mousemove', (e) => {
if (isDragging) {
let newLeft = e.clientX - offsetX;
let newTop = e.clientY - offsetY;
// This prevents the user from dragging the app window off the screen, potentially losing it.
newLeft = Math.max(0, Math.min(newLeft, window.innerWidth - windowElement.offsetWidth));
newTop = Math.max(0, Math.min(newTop, window.innerHeight - windowElement.offsetHeight));
windowElement.style.left = `${newLeft}px`;
windowElement.style.top = `${newTop}px`;
}
});
document.addEventListener('mouseup', () => {
isDragging = false;
});
});
// This disables the user's ability to use the right-click or 'context' menu.
document.addEventListener('contextmenu', function (event) {
event.preventDefault();
});
// This opens the Welcome app when the web desktop loads completely.
// Change the app ID to make a different app be the default one to open.
window.onload = function () {
openWindow('updates');
}