-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
58 lines (49 loc) · 1.91 KB
/
script.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
var isDragging = false;
var offsetX = 0;
var offsetY = 0;
var zIndexCounter = 1000; // Starting z-index value
function openWindow(windowId) {
var windowElement = document.getElementById(windowId);
if (windowElement) {
zIndexCounter++; // Increment the z-index for the new window
windowElement.style.zIndex = zIndexCounter; // Set the z-index
windowElement.style.display = "block";
adjustIframeHeight(windowElement);
// Center the window
windowElement.style.top = '50%';
windowElement.style.left = '50%';
windowElement.style.transform = 'translate(-50%, -50%)';
var titleBar = windowElement.querySelector('.title-bar');
titleBar.addEventListener('mousedown', function (e) {
isDragging = true;
offsetX = e.clientX - windowElement.getBoundingClientRect().left;
offsetY = e.clientY - windowElement.getBoundingClientRect().top;
bringWindowToFront(windowElement);
});
window.addEventListener('mousemove', dragWindow);
window.addEventListener('mouseup', function () {
isDragging = false;
});
}
}
function closeWindow(windowId) {
var windowElement = document.getElementById(windowId);
if (windowElement) {
windowElement.style.display = "none";
// Remove event listeners when the window is closed
window.removeEventListener('mousemove', dragWindow);
}
}
function dragWindow(e) {
if (isDragging) {
var windowElement = document.querySelector('.window');
if (windowElement) {
windowElement.style.left = e.clientX - offsetX + 'px';
windowElement.style.top = e.clientY - offsetY + 'px';
}
}
}
function bringWindowToFront(windowElement) {
zIndexCounter++; // Increment the z-index when a window is clicked
windowElement.style.zIndex = zIndexCounter; // Set the updated z-index
}