-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
104 lines (86 loc) · 3.7 KB
/
script.js
File metadata and controls
104 lines (86 loc) · 3.7 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
document.addEventListener("DOMContentLoaded", function() {
let lists = document.getElementsByClassName("team");
let rightBox = document.getElementById("right");
let leftBox = document.getElementById("left");
let dropdownBtns = document.getElementsByClassName("dropdown-btn");
function closeAllDropdowns() {
let dropdownContents = document.getElementsByClassName("dropdown-content");
for (let i = 0; i < dropdownContents.length; i++) {
dropdownContents[i].style.display = "none";
}
}
// Dropdown lists are closed first
closeAllDropdowns();
for (let team of lists) {
team.addEventListener("dragstart", function(e) {
let selected = e.target;
rightBox.addEventListener("dragover", function(e) {
e.preventDefault();
});
rightBox.addEventListener("drop", function(e) {
if (rightBox.children.length === 0) {
rightBox.appendChild(selected);
selected = null;
rightBox.removeEventListener("dragover", dragOver);
rightBox.removeEventListener("drop", drop);
}
});
leftBox.addEventListener("dragover", function(e) {
e.preventDefault();
});
leftBox.addEventListener("drop", function(e) {
if (leftBox.children.length === 0) {
leftBox.appendChild(selected);
selected = null;
leftBox.removeEventListener("dragover", dragOver);
leftBox.removeEventListener("drop", drop);
}
});
});
}
leftBox.addEventListener("dblclick", function(e) {
let item = e.target;
if (item.classList.contains("team")) {
item.parentNode.removeChild(item);
document.querySelector(".pick").appendChild(item);
}
});
rightBox.addEventListener("dblclick", function(e) {
let item = e.target;
if (item.classList.contains("team")) {
item.parentNode.removeChild(item);
document.querySelector(".pick").appendChild(item);
}
});
});
document.addEventListener("DOMContentLoaded", function() {
let dropdownBtns = document.getElementsByClassName("dropdown-btn");
function closeAllDropdowns() {
let dropdownContents = document.getElementsByClassName("dropdown-content");
for (let i = 0; i < dropdownContents.length; i++) {
dropdownContents[i].style.display = "none";
}
}
// Dropdown lists are closed first
closeAllDropdowns();
// Event Listener that reacts to click on interactive objects (ex: buttons...)
for (let i = 0; i < dropdownBtns.length; i++) {
dropdownBtns[i].addEventListener("click", function(e) {
e.stopPropagation();
let dropdownContent = this.nextElementSibling;
while (dropdownContent && !dropdownContent.classList.contains("dropdown-content")) {
dropdownContent = dropdownContent.nextElementSibling;
}
if (dropdownContent) {
// Closes an open dropdown
if (dropdownContent.style.display === "block") {
dropdownContent.style.display = "none";
} else {
// Closes all dropdown lists when opening one to avoid filling up screen
closeAllDropdowns();
dropdownContent.style.display = "block";
}
}
});
}
});