-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsectionManager.js
More file actions
77 lines (64 loc) · 2.25 KB
/
Copy pathsectionManager.js
File metadata and controls
77 lines (64 loc) · 2.25 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
// ========================================
// Section Manager - Handles navigation between sections
// ========================================
const SectionManager = {
sections: ['home', 'game', 'about', 'policies', 'terms', 'contact'],
currentSection: 'home',
init() {
// Setup navigation links
document.querySelectorAll('.sidebar-links a, .nav-links a').forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const section = link.getAttribute('data-section');
if (section) {
this.showSection(section);
}
});
});
// Handle hash change
window.addEventListener('hashchange', () => {
this.handleHash();
});
// Initial hash handling
this.handleHash();
},
showSection(section) {
if (!this.sections.includes(section)) {
section = 'home';
}
// Hide all sections
this.sections.forEach(s => {
const el = document.getElementById(`${s}Section`);
if (el) {
el.style.display = 'none';
}
});
// Show selected section
const targetSection = document.getElementById(`${section}Section`);
if (targetSection) {
targetSection.style.display = 'block';
}
this.currentSection = section;
window.location.hash = section;
// Special handling for game section (refresh iframe)
if (section === 'game') {
const gameIframe = document.getElementById('gameIframe');
if (gameIframe && gameIframe.src && !gameIframe.src.includes('game.html')) {
gameIframe.src = 'game.html';
}
}
console.log(`Section changed to: ${section}`);
},
handleHash() {
const hash = window.location.hash.substring(1);
if (hash && this.sections.includes(hash)) {
this.showSection(hash);
} else {
this.showSection('home');
}
},
getCurrentSection() {
return this.currentSection;
}
};
window.SectionManager = SectionManager;