-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
206 lines (178 loc) · 8.94 KB
/
script.js
File metadata and controls
206 lines (178 loc) · 8.94 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
// script.js
document.addEventListener('DOMContentLoaded', () => {
// --- Smooth Scrolling for Nav Links ---
const navLinks = document.querySelectorAll('.nav-link[href^="#"]');
navLinks.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetElement = document.querySelector(targetId);
if (targetElement) {
// Calculate position considering fixed navbar height
const navbarHeight = document.getElementById('navbar').offsetHeight;
const elementPosition = targetElement.getBoundingClientRect().top;
const offsetPosition = elementPosition + window.pageYOffset - navbarHeight;
window.scrollTo({
top: offsetPosition,
behavior: 'smooth'
});
}
// Close mobile menu if open
if (document.getElementById('navLinks').classList.contains('active')) {
document.getElementById('navLinks').classList.remove('active');
document.getElementById('menuToggle').setAttribute('aria-expanded', 'false');
document.getElementById('menuToggle').innerHTML = '<i class="fas fa-bars"></i>';
}
});
});
// --- Mobile Navigation Toggle ---
const menuToggle = document.getElementById('menuToggle');
const mainNavLinks = document.getElementById('navLinks'); // Renamed to avoid conflict
if (menuToggle && mainNavLinks) {
menuToggle.addEventListener('click', () => {
mainNavLinks.classList.toggle('active');
const isExpanded = mainNavLinks.classList.contains('active');
menuToggle.setAttribute('aria-expanded', isExpanded);
if (isExpanded) {
menuToggle.innerHTML = '<i class="fas fa-times"></i>'; // Change to X icon
} else {
menuToggle.innerHTML = '<i class="fas fa-bars"></i>'; // Change back to bars
}
});
}
// --- "Check Your Time" Modal Logic ---
const timeModal = document.getElementById('timeModal');
const openTimeModalBtn = document.getElementById('openTimeModalBtn');
const closeTimeModalBtn = document.getElementById('closeTimeModalBtn');
const checkTimeBtn = document.getElementById('checkTimeBtn');
const operativeIdInput = document.getElementById('operativeId');
const timeResultDiv = document.getElementById('timeResult');
if (openTimeModalBtn) {
openTimeModalBtn.onclick = function() {
timeModal.classList.add('active');
operativeIdInput.focus();
}
}
if (closeTimeModalBtn) {
closeTimeModalBtn.onclick = function() {
timeModal.classList.remove('active');
timeResultDiv.innerHTML = 'Awaiting Operative ID...'; // Reset result
operativeIdInput.value = ''; // Clear input
}
}
// Close modal if clicked outside of modal-content
window.onclick = function(event) {
if (event.target == timeModal) {
timeModal.classList.remove('active');
timeResultDiv.innerHTML = 'Awaiting Operative ID...';
operativeIdInput.value = '';
}
if (event.target == galleryModal) {
galleryModal.classList.remove('active');
}
}
// Handle Escape key to close modals
document.addEventListener('keydown', function(event) {
if (event.key === "Escape") {
if (timeModal.classList.contains('active')) {
timeModal.classList.remove('active');
timeResultDiv.innerHTML = 'Awaiting Operative ID...';
operativeIdInput.value = '';
}
if (galleryModal.classList.contains('active')) {
galleryModal.classList.remove('active');
}
}
});
if (checkTimeBtn) {
checkTimeBtn.onclick = async function() {
const username = operativeIdInput.value.trim();
if (!username) {
timeResultDiv.innerHTML = '<p class="error">Please enter an Operative ID.</p>';
return;
}
timeResultDiv.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Querying the Chrono-Stream...';
// **MOCK FIREBASE INTEGRATION**
// Replace this with your actual Firebase Cloud Function call
try {
// Simulate API call delay
await new Promise(resolve => setTimeout(resolve, 1500));
// Mocked responses
const mockData = {
"ChronoAgent42": { hours: 10, minutes: 32, seconds: 15 },
"TimeBender007": { hours: 0, minutes: 5, seconds: 59 },
"CubeRunnerX": { hours: 100, minutes: 0, seconds: 0 },
};
if (mockData[username]) {
const timeData = mockData[username];
timeResultDiv.innerHTML = `
<p class="success">
<strong>${username}</strong>, your remaining Chrono-Reserve: <br>
<span style="font-size: 1.8rem; color: var(--primary-color); display: block; margin-top: 10px;">
${String(timeData.hours).padStart(2, '0')} Hours
${String(timeData.minutes).padStart(2, '0')} Minutes
${String(timeData.seconds).padStart(2, '0')} Seconds
</span>
<br>(This is your lifeline. Use it wisely.)
</p>`;
} else {
timeResultDiv.innerHTML = `
<p class="error">
OPERATIVE ID <strong>"${username}"</strong> NOT FOUND OR DATA UNAVAILABLE.
<br>(Ensure your ID is correct or that you have initiated your journey within The Cube.)
</p>`;
}
} catch (error) {
console.error("Error fetching time (mock):", error);
timeResultDiv.innerHTML = '<p class="error">Error connecting to the Chrono-Core. Please try again later.</p>';
}
}
}
// --- Gallery Modal Logic ---
const galleryModal = document.getElementById('galleryModal');
const closeGalleryModalBtn = document.getElementById('closeGalleryModalBtn');
const galleryModalContentArea = document.getElementById('galleryModalContentArea');
const galleryModalCaption = document.getElementById('galleryModalCaption');
window.openImageModal = function(src, alt) {
galleryModalContentArea.innerHTML = `<img src="https://limeless-studio.github.io/thecube-kit${src}" alt="${alt}">`;
galleryModalCaption.textContent = alt;
galleryModal.classList.add('active');
}
window.openVideoModal = function(youtubeVideoId) {
// Ensure you use the YouTube embed URL format
const embedUrl = `https://www.youtube.com/embed/${youtubeVideoId}?autoplay=1&rel=0`;
galleryModalContentArea.innerHTML = `<iframe width="560" height="315" src="https://limeless-studio.github.io/thecube-kit${embedUrl}" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>`;
galleryModalCaption.textContent = "Game Trailer"; // Or fetch title if needed
galleryModal.classList.add('active');
}
if (closeGalleryModalBtn) {
closeGalleryModalBtn.onclick = function() {
galleryModal.classList.remove('active');
galleryModalContentArea.innerHTML = ''; // Clear content to stop video, etc.
galleryModalCaption.textContent = '';
}
}
// --- Dynamic Year for Footer ---
const currentYearSpan = document.getElementById('currentYear');
if (currentYearSpan) {
currentYearSpan.textContent = new Date().getFullYear();
}
// --- Active Nav Link Highlighting on Scroll ---
const sections = document.querySelectorAll('section[id], header[id]'); // Include header for hero
const navbarHeight = document.getElementById('navbar').offsetHeight;
function changeNavActiveState() {
let index = sections.length;
while(--index && window.scrollY + navbarHeight + 50 < sections[index].offsetTop) {} // 50 is an offset
navLinks.forEach((link) => link.classList.remove('active'));
// Ensure the link exists before trying to add 'active' class
const activeLink = document.querySelector(`.nav-link[href="#${sections[index].id}"]`);
if (activeLink) {
activeLink.classList.add('active');
}
}
// Initial call to set active link on page load (if not at the very top)
if (window.scrollY > 0) {
changeNavActiveState();
}
window.addEventListener('scroll', changeNavActiveState);
});