-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
193 lines (166 loc) · 6.98 KB
/
script.js
File metadata and controls
193 lines (166 loc) · 6.98 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
document.addEventListener('DOMContentLoaded', function() {
// --- Navbar loader ---
// Load Navbar dynamically into the placeholder
const navbarPlaceholder = document.getElementById('navbar-placeholder');
if (navbarPlaceholder) {
fetch('Navbar.html')
.then(response => {
if (!response.ok) {
throw new Error('Failed to load Navbar.html: ' + response.statusText);
}
return response.text();
})
.then(html => {
navbarPlaceholder.innerHTML = html;
// Wait for DOM insertion to complete
setupNavbarToggle();
})
.catch(error => console.error('Navbar load error:', error));
}
function setupNavbarToggle() {
const hamburger = document.getElementById("hamburger");
const navLinks = document.getElementById("navLinks");
if (hamburger && navLinks) {
hamburger.addEventListener("click", () => {
navLinks.classList.toggle("active");
});
} else {
console.warn("Hamburger or navLinks not found in loaded Navbar.");
}
}
// --- Footer loader ---
const footerPlaceholder = document.getElementById('footer-placeholder');
if (footerPlaceholder) {
fetch('footer.html') // Ensure this path and filename are correct ('Footer.html' vs 'footer.html')
.then(response => {
if (!response.ok) {
throw new Error('Network response for Footer.html was not ok: ' + response.statusText);
}
return response.text();
})
.then(html => {
footerPlaceholder.innerHTML = html;
})
.catch(error => console.error('Failed to load footer:', error));
}
// --- Global Register Button & Blur Overlay Logic ---
const globalRegisterButtonContainer = document.querySelector('.global-register-button-container');
const mainRegisterBtn = document.getElementById('mainRegisterBtn'); // Ensure this ID matches your HTML button
const blurOverlay = document.getElementById('blurOverlay'); // Select the blur overlay
let isRegisterButtonVisible = false; // Flag to track button visibility
// Function to show the button and blur
function showRegisterButton() {
if (globalRegisterButtonContainer) {
globalRegisterButtonContainer.classList.add('active');
isRegisterButtonVisible = true;
}
if (blurOverlay) {
blurOverlay.classList.add('active'); // Activate the blur overlay
}
}
// Function to hide the button and unblur
function hideRegisterButton() {
if (globalRegisterButtonContainer) {
globalRegisterButtonContainer.classList.remove('active');
isRegisterButtonVisible = false;
}
if (blurOverlay) {
blurOverlay.classList.remove('active'); // Deactivate the blur overlay
}
}
// --- Event Image Click Logic (to show global button and blur) ---
// Select the parent .event-item divs, as clicks on them are usually desired.
// If you explicitly only want clicks on the <img> tag itself, change to '.event-image'
const eventItems = document.querySelectorAll('.event-image');
eventItems.forEach(item => {
item.addEventListener('click', function() {
if (!isRegisterButtonVisible) { // Only show if not already visible
showRegisterButton();
}
// If the button is already visible, clicking another image won't hide it.
});
});
// --- What happens when the Main Register Button itself is clicked ---
if (mainRegisterBtn) {
mainRegisterBtn.addEventListener('click', function(event) {
event.stopPropagation(); // Prevent this click from bubbling up to document and hiding the button immediately
openLoginPopup(); // Open the login popup
});
}
document.addEventListener('click', function(event) {
if (isRegisterButtonVisible) { // Only act if the button is currently visible
const clickedElement = event.target;
// Check if the click is inside the button container
// (i.e., on the button itself or any element within its container)
const isClickInsideButtonContainer = globalRegisterButtonContainer.contains(clickedElement);
// Check if the click is on any of the event images/cards
// (i.e., on an .event-item div or any element within an .event-item)
const isClickOnEventItem = Array.from(eventItems).some(item => item.contains(clickedElement));
// If the click was NOT inside the button/its container
// AND was NOT on an event image/card, then hide
if (!isClickInsideButtonContainer && !isClickOnEventItem) {
hideRegisterButton();
}
}
});
function animateAndRedirectTo(url) {
document.body.classList.add("fade-out");
setTimeout(() => {
window.location.href = url;
}, 6000); // Match CSS duration
}
window.addEventListener("DOMContentLoaded", () => {
document.body.classList.add("fade-in");
});
});
function openLoginPopup() {
// Create the popup container
const popupContainer = document.createElement('div');
popupContainer.className = 'popup-container';
// Create the popup content
const popupContent = document.createElement('div');
popupContent.className = 'popup-content';
// Add a close button
const closeButton = document.createElement('span');
closeButton.className = 'close-button';
closeButton.innerHTML = '×';
closeButton.onclick = function () {
document.body.removeChild(popupContainer);
};
// Append close button immediately (before loading)
popupContent.appendChild(closeButton);
// Fetch the actual login.html content and inject into popup
fetch('login.html')
.then(response => {
if (!response.ok) throw new Error('Failed to load login.html');
return response.text();
})
.then(html => {
const wrapper = document.createElement('div');
wrapper.innerHTML = html;
popupContent.appendChild(wrapper);
})
.catch(err => {
const errorMsg = document.createElement('p');
errorMsg.textContent = 'Error loading login form.';
popupContent.appendChild(errorMsg);
console.error(err);
});
// Append content to the container and container to body
popupContainer.appendChild(popupContent);
document.body.appendChild(popupContainer);
popupContainer.addEventListener('click', function (event) {
if (!popupContent.contains(event.target)) {
document.body.removeChild(popupContainer);
}
});
}
function animateAndRedirectTo(url) {
document.body.classList.add("fade-out");
setTimeout(() => {
window.location.href = url;
}, 600); // Match CSS duration
}
window.addEventListener("DOMContentLoaded", () => {
document.body.classList.add("fade-in");
});