-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
61 lines (50 loc) · 1.8 KB
/
script.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const humans_parent = document.getElementById("humans");
const BLOOD_TYPES = {
"O−": ["O−", "O+", "A−", "A+", "B−", "B+", "AB−", "AB+"],
"O+": ["O+", "A+", "B+", "AB+"],
"A−": ["A−", "A+", "AB−", "AB+"],
"A+": ["A+", "AB+"],
"B−": ["B−", "B+", "AB−", "AB+"],
"B+": ["B+", "AB+"],
"AB−": ["AB−", "AB+"],
"AB+": ["AB+"],
};
const selector = document.getElementById("blood_selector");
const blood_vias = document.querySelectorAll("#humans .human .blood_via");
const blood_bag = document.querySelector("#blood_content > div.main_bag > div");
const center_via = document.querySelector(".center_via > .blood_via");
const blood_types = document.querySelectorAll(".blood_type");
let lastCalled;
addListeners();
function callIfChildren(e) {
if (lastCalled) change();
if (e.target !== this) setRecipents(e);
}
function addListeners() {
selector.addEventListener("click", callIfChildren);
}
function change() {
lastCalled.target.classList.remove("highlight");
for (let i = 0; i < blood_vias.length; i++) {
blood_vias[i].style.width = "0px";
blood_types[i].classList.remove("highlightText");
}
}
function timeout(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
async function setRecipents(e) {
e.target.classList.add("highlight");
lastCalled = e;
const donor = e.target.innerText;
for (let item of BLOOD_TYPES[donor]) {
const recipent_index = Object.keys(BLOOD_TYPES).indexOf(item);
const height = 50 + 50 * Math.floor(recipent_index / 2);
const blood_height = 125 - 25 * Math.floor(recipent_index / 2);
blood_bag.style.height = `${blood_height}px`;
center_via.style.height = `${height}px`;
await timeout(100);
blood_vias[recipent_index].style.width = "100%";
blood_types[recipent_index].classList.add("highlightText");
}
}