-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaster.js
More file actions
59 lines (50 loc) · 1.65 KB
/
master.js
File metadata and controls
59 lines (50 loc) · 1.65 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
document.addEventListener('DOMContentLoaded', () => {
const allDetails = Array.from(document.querySelectorAll('details'));
let isMobile = window.innerWidth <= 1000;
const cardOrder = ['interaction', 'dialogue', 'inventory', 'director', 'launcher', 'dialoguer', 'inventoryManager', 'buildTool'];
async function loadDesktopCards() {
const wrapper = document.querySelector('.accordion-wrapper');
wrapper.innerHTML = '';
for (const cardId of cardOrder) {
try {
const response = await fetch(`pages/${cardId}.html`);
const html = await response.text();
wrapper.insertAdjacentHTML('beforeend', html);
} catch (error) {
console.error(`Failed to load ${cardId}:`, error);
}
}
const loadedDetails = Array.from(document.querySelectorAll('details'));
allDetails.splice(0, allDetails.length, ...loadedDetails);
initDesktop();
}
function initDesktop() {
allDetails.forEach(detail => {
detail.addEventListener('toggle', () => {
if (detail.open) {
allDetails.forEach(other => {
if (other !== detail && other.open) {
other.open = false;
}
});
}
detail.classList.remove('animate-in');
if (detail.open) {
void detail.offsetWidth;
detail.classList.add('animate-in');
}
});
});
}
function handleResize() {
const newIsMobile = window.innerWidth <= 1000;
if (newIsMobile !== isMobile) {
isMobile = newIsMobile;
location.reload();
}
}
if (!isMobile) {
loadDesktopCards();
}
window.addEventListener('resize', handleResize);
});