-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
242 lines (197 loc) · 7.5 KB
/
Copy pathscript.js
File metadata and controls
242 lines (197 loc) · 7.5 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
// Make the DIV element draggable:
var biggestIndex = 1;
// Step 1: Define a function called `dragElement` that makes an HTML element draggable.
function dragElement(element) {
// Step 2: Set up variables to keep track of the element's position.
var initialX = 0;
var initialY = 0;
var currentX = 0;
var currentY = 0;
// Step 3: Check if there is a special header element associated with the draggable element.
if (document.getElementById(element.id + "header")) {
// Step 4: If present, assign the `dragMouseDown` function to the header's `onmousedown` event.
// This allows you to drag the window around by its header.
document.getElementById(element.id + "header").onmousedown = startDragging;
} else {
// Step 5: If not present, assign the function directly to the draggable element's `onmousedown` event.
// This allows you to drag the window by holding down anywhere on the window.
element.onmousedown = startDragging;
}
// Step 6: Define the `startDragging` function to capture the initial mouse position and set up event listeners.
function startDragging(e) {
if (element.classList.contains("maximized"))
return;
e = e || window.event;
e.preventDefault();
// Step 7: Get the mouse cursor position at startup.
initialX = e.clientX;
initialY = e.clientY;
// Step 8: Set up event listeners for mouse movement (`elementDrag`) and mouse button release (`closeDragElement`).
document.onmouseup = stopDragging;
document.onmousemove = dragElement;
}
// Step 9: Define the `elementDrag` function to calculate the new position of the element based on mouse movement.
function dragElement(e) {
e = e || window.event;
e.preventDefault();
// Step 10: Calculate the new cursor position.
currentX = initialX - e.clientX;
currentY = initialY - e.clientY;
initialX = e.clientX;
initialY = e.clientY;
// Step 11: Update the element's new position by modifying its `top` and `left` CSS properties.
element.style.top = (element.offsetTop - currentY) + "px";
element.style.left = (element.offsetLeft - currentX) + "px";
}
// Step 12: Define the `stopDragging` function to stop tracking mouse movement by removing the event listeners.
function stopDragging() {
document.onmouseup = null;
document.onmousemove = null;
}
}
function closeWindow(element) {
element.style.display = "none"
if (element.id === "eaglercraft") {
element.querySelector("#eaglercraftcontent").innerHTML = "";
}
}
function openWindow(element) {
console.trace("Opening:", element.id);
element.style.display = "flex"
biggestIndex++; // Increment biggestIndex by 1
element.style.zIndex = biggestIndex;
if (element.id === "eaglercraft") {
const content = element.querySelector("#eaglercraftcontent");
if (content.innerHTML === "") {
content.innerHTML = `
<iframe
src="eaglercraftX.html"
style="width:100%;height:100%;border:none;">
</iframe>
`;
}
}
}
function initialiseWindow(windowid, idopen, idclose, header, idmaximise)
{
dragElement(document.getElementById(windowid));
var elementopen = document.querySelector("#" + idopen);
var elementclose = document.querySelector("#" + idclose);
var element = document.querySelector("#" + windowid);
var elementmaximise = document.querySelector("#" + idmaximise);
addWindowTapHandling(element);
const elementWindow = document.getElementById(windowid);
console.log(windowid, idmaximise, elementmaximise);
if(!elementmaximise)
{
console.error("Couldn't find: ", idmaximise);
}
elementopen.addEventListener("click", function() {
openWindow(elementWindow);
})
elementclose.addEventListener("click", function() {
closeWindow(elementWindow);
})
elementmaximise.addEventListener("click", function() {
toggleMaximize(elementWindow);
})
}
function addWindowTapHandling(element) {
element.addEventListener("mousedown", () =>
handleWindowTap(element)
)
}
function handleWindowTap(element) {
biggestIndex++; // Increment biggestIndex by 1
element.style.zIndex = biggestIndex;
}
function updateTime() {
var currentTime = new Date().toLocaleString();
var timeText = document.querySelector("#timeElement");
timeText.innerHTML = currentTime;
}
setInterval(updateTime, 1000);
function toggleMaximize(element) {
const button = element.querySelector(".maximize_button");
if (!element.classList.contains("maximized")) {
// Save current position & size
element.dataset.oldTop = element.style.top;
element.dataset.oldLeft = element.style.left;
element.dataset.oldWidth = element.style.width;
element.dataset.oldHeight = element.style.height;
element.classList.add("maximized");
} else {
element.classList.remove("maximized");
element.style.top = element.dataset.oldTop;
element.style.left = element.dataset.oldLeft;
element.style.width = element.dataset.oldWidth;
element.style.height = element.dataset.oldHeight;
}
handleWindowTap(element);
}
var content = [
{
title: "Welcome",
date: "13/07/2026",
content: `
<p contenteditable="True">
<span contenteditable="true">Welcome to <strong>Journel</strong>
</br>
</br>
<img src=""
style="width: 96px; border-radius: 16px" />
</br>
</br>
This is a place where I store my thoughts as they come to mind. What exactly will you find when browsing
through
these notes? As I <del>once said</del> <ins>always say</ins>
</span>
<blockquote
style="background-color: #b4b1b182; margin-top: 16x; margin-bottom: 16px; margin-left: 0px; margin-right: 0px; padding: 16px;"
contenteditable="true">
<i>i love potatoes
</br>
~ speed
</i>
</blockquote>
<span contenteditable="true">
I suppose you may see a bit of content about technology. Perhaps some insights regarding recent projects.
Maybe
even some thoughts regarding nature & tea? Go and find out!
</span>
</p>
`
}
];
function setNotesContent(index) {
var notesContent = document.querySelector("#notescontent")
notesContent.innerHTML = content[index].content
}
setNotesContent(0)
function addToSideBar(index)
{
var sidebar = document.querySelector("#sidebar");
var note = content[index];
var newDiv = document.createElement("div");
newDiv.innerHTML = `
<p style="margin: 0px;">
${note.title}
</p>
<p style="font-size: 12px; margin: 0px;">
${note.date}
</p>
`;
newDiv.addEventListener("click", function() {
setNotesContent(index);
});
sidebar.appendChild(newDiv);
}
for (let i = 0; i < content.length; i++) {
addToSideBar(i)
}
initialiseWindow("hobbies", "hobbyopen", "hobbyclose", "hobbiesheader", "hobbymaximise");
initialiseWindow("server", "serveropen", "serverclose", "serverheader", "servermaximise");
initialiseWindow("playlists", "playlistsopen", "playlistsclose", "playlistsheader", "playlistmaximise");
initialiseWindow("notes", "notesopen", "notesclose", "notesheader", "notesmaximise");
initialiseWindow("info", "infoopen", "infoclose", "infoheader", "infomaximise");
initialiseWindow("eaglercraft", "eaglercraftopen", "eaglercraftclose", "eaglercraftheader", "eaglercraftmaximise");