This repository was archived by the owner on May 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
54 lines (46 loc) · 1.43 KB
/
script.js
File metadata and controls
54 lines (46 loc) · 1.43 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
const mapFrame = document.getElementById('map');
const navbar = document.getElementById('navbar');
const maps = [
{
url: 'https://creativemap.pcbmc.co',
linkElement: document.getElementById('creative-link'),
},
{
url: 'https://survivalmap.pcbmc.co',
linkElement: document.getElementById('survival-link'),
},
{
url: 'https://3d.pcbmc.co',
linkElement: document.getElementById('monarch-link'),
},
]
function setActiveLink(map) {
maps.forEach((map) => {
map.linkElement.classList.remove('active');
});
map.linkElement.classList.add('active');
mapFrame.src = map.url;
}
function resizeMapFrame() {
// Compensate for browser inconsistency
const windowHeight = Math.max(
document.body.scrollHeight, document.documentElement.scrollHeight,
document.body.offsetHeight, document.documentElement.offsetHeight,
document.body.clientHeight, document.documentElement.clientHeight
);
mapFrame.height = windowHeight - navbar.offsetHeight;
}
window.onload = () => {
resizeMapFrame();
setActiveLink(maps[0]);
}
// Force resize as soon as possible, because onload fires quite late
document.onreadystatechange = (event) => {
if (document.readyState === 'complete') {
resizeMapFrame();
}
};
window.onresize = resizeMapFrame
maps.forEach((map) => {
map.linkElement.addEventListener('click', () => setActiveLink(map))
});