-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
132 lines (107 loc) · 3.78 KB
/
script.js
File metadata and controls
132 lines (107 loc) · 3.78 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
document.addEventListener("DOMContentLoaded", function () {
const windows = document.querySelectorAll(".window");
// getting current screen height. currently used for centering stuff without css cuz fuck css
// but could later be used for mobile builds
var w = window.innerWidth;
var h = window.innerHeight;
// console.log("browser window width: ", w);
// console.log("browser window height: ", h);
let activeWindow = null;
let initialX, initialY;
// open greetings by default
if (shouldRunOnFirstVisit) {
openGreetings();
}
// Event listener for opening windows
const openButtons = document.querySelectorAll(".open-window-button");
openButtons.forEach((button) => {
button.addEventListener("click", function () {
const imageId = button.id;
const windowId = "window-" + imageId;
const window = document.getElementById(windowId);
if (window) {
window.style.display = "block";
centerWindow(window);
bringWindowToFront(window);
}
});
});
// Event listener for closing windows
const closeButtons = document.querySelectorAll(".close-button");
closeButtons.forEach((button) => {
button.addEventListener("click", function () {
const window = button.closest(".window");
if (window) {
window.style.display = "none";
}
});
});
// Event listeners for dragging windows
windows.forEach((window) => {
const topBar = window.querySelector(".window-top-bar");
topBar.addEventListener("mousedown", (e) => {
activeWindow = window;
initialX = e.clientX - window.getBoundingClientRect().left;
initialY = e.clientY - window.getBoundingClientRect().top;
bringWindowToFront(window);
});
});
document.addEventListener("mousemove", (e) => {
if (!activeWindow) return;
const left = e.clientX - initialX;
const top = e.clientY - initialY;
activeWindow.style.left = left + "px";
activeWindow.style.top = top + "px";
});
document.addEventListener("mouseup", () => {
activeWindow = null;
});
// Get a reference to the buttons and the window
const thankYouButton = document.querySelector(
".paradise-button:nth-child(1)"
);
const farewellButton = document.querySelector(
".paradise-button:nth-child(2)"
);
const windowElement = document.getElementById("window-win-paradiseanywhere");
// Function to close the window
function closeWindow() {
windowElement.style.display = "none";
}
// Add click event listeners to the buttons
thankYouButton.addEventListener("click", closeWindow);
farewellButton.addEventListener("click", closeWindow);
//bring a window to the front by setting a higher z-index
function bringWindowToFront(window) {
windows.forEach((w) => {
w.style.zIndex = w === window ? "9999" : "1";
});
}
function centerWindow(windowToCenter) {
// centering window on click
const windowWidth = windowToCenter.offsetWidth;
const windowHeight = windowToCenter.offsetHeight;
windowToCenter.style.left = w / 2 - windowWidth / 2 + "px";
windowToCenter.style.top = h / 2 - windowHeight / 2 + "px";
}
function shouldRunOnFirstVisit() {
// Check if a flag exists in local storage
const hasVisitedBefore = localStorage.getItem("hasVisitedBefore");
// If the flag exists and is set to 'true', return false
if (hasVisitedBefore === "true") {
return false;
}
// Otherwise, set the flag in local storage and return true
localStorage.setItem("hasVisitedBefore", "true");
return true;
}
function openGreetings() {
const windowId = "window-win-paradiseanywhere";
const window = document.getElementById(windowId);
if (window) {
window.style.display = "block";
centerWindow(window);
bringWindowToFront(window);
}
}
});