-
Notifications
You must be signed in to change notification settings - Fork 1
/
levelsel.js
47 lines (41 loc) · 1.29 KB
/
levelsel.js
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
var levelFiles = [
{name: "Level 1", file: "level1.json"},
{name: "Level 2", file: "level2.json"},
{name: "Cancel", file: "null"}
];
function showLevelSelect(el) {
var bbox = el.getBoundingClientRect();
var targetX = bbox.left;
var targetY = bbox.bottom;
var targetW = bbox.width;
var container = document.createElement("div");
container.id = "levelSelect";
container.style.position = "fixed";
container.style.left = targetX + "px";
container.style.top = targetY + "px";
container.style.width = targetW + "px";
container.style.backgroundColor = "#fff";
container.style.color = "black";
container.style.fontSize = "14px";
container.style.fontFamily = "sans-serif";
for(var i = 0; i < levelFiles.length; i++) {
var data = levelFiles[i];
var item = document.createElement("div");
item.style.padding = "5px";
item.innerText = data.name;
item.dataset.file = data.file;
item.onclick = function() {
hideLevelSelect();
if(this.dataset.file != "null") {
importGameURL(this.dataset.file);
resetTime();
}
};
container.appendChild(item);
}
document.body.appendChild(container);
}
function hideLevelSelect() {
var container = document.getElementById("levelSelect");
document.body.removeChild(container);
}