-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDixon12WorkingJS.js
100 lines (81 loc) · 3.05 KB
/
Dixon12WorkingJS.js
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// script.js
document.getElementById('start-button').addEventListener('click', () => {
const startMenu = document.getElementById('start-menu');
startMenu.classList.toggle('hidden');
});
document.getElementById('notepad-icon').addEventListener('click', () => {
openWindow('notepad-window');
});
document.getElementById('browser-icon').addEventListener('click', () => {
openWindow('browser-window');
});
document.getElementById('calculator-icon').addEventListener('click', () => {
openWindow('calculator-window');
});
document.getElementById('settings-icon').addEventListener('click', () => {
openWindow('settings-window');
});
document.getElementById('open-notepad').addEventListener('click', () => {
openWindow('notepad-window');
toggleStartMenu();
});
document.getElementById('open-browser').addEventListener('click', () => {
openWindow('browser-window');
toggleStartMenu();
});
document.getElementById('open-calculator').addEventListener('click', () => {
openWindow('calculator-window');
toggleStartMenu();
});
document.getElementById('open-settings').addEventListener('click', () => {
openWindow('settings-window');
toggleStartMenu();
});
document.querySelectorAll('.close').forEach(closeButton => {
closeButton.addEventListener('click', (event) => {
closeButton.parentElement.parentElement.classList.add('hidden');
});
});
function openWindow(windowId) {
document.getElementById(windowId).classList.remove('hidden');
}
function toggleStartMenu() {
document.getElementById('start-menu').classList.toggle('hidden');
}
// Dragging functionality
document.querySelectorAll('.window').forEach(window => {
const header = window.querySelector('.window-header');
let isDragging = false;
let offsetX, offsetY;
header.addEventListener('mousedown', (event) => {
isDragging = true;
offsetX = event.clientX - window.offsetLeft;
offsetY = event.clientY - window.offsetTop;
});
document.addEventListener('mousemove', (event) => {
if (isDragging) {
window.style.left = `${event.clientX - offsetX}px`;
window.style.top = `${event.clientY - offsetY}px`;
}
});
document.addEventListener('mouseup', () => {
isDragging = false;
});
});
function updateClock() {
const now = new Date();
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
document.getElementById('clock').textContent = `${hours}:${minutes}`;
}
// Initial clock update and then update every minute
updateClock();
setInterval(updateClock, 60000);
document.getElementById('shutdown-button').addEventListener('click', () => {
document.getElementById('main-screen').classList.add('hidden');
document.getElementById('shutdown-screen').classList.remove('hidden');
});
document.getElementById('turn-on-button').addEventListener('click', () => {
document.getElementById('shutdown-screen').classList.add('hidden');
document.getElementById('main-screen').classList.remove('hidden');
});