-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton.html
158 lines (142 loc) · 5.04 KB
/
button.html
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<!-- Who see's it? -->
<title>Butter - Keep Talking</title>
<style>
.btnActive {
box-shadow: 0px 0px 10px orange;
}
label {
border: 1px solid black;
border-radius: 5px;
padding: 5px;
display: block;
}
.btnBlue {
background-color: blue;
color: white;
}
.btnRed {
background-color: red;
color: white;
}
.btnWhite {
background-color: white;
color: black;
}
.btnYellow {
background-color: yellow;
color: black;
}
.btnOther {
background-color: darkgrey;
color: black;
}
input[type="radio"] {
display: none;
}
</style>
</head>
<body>
<h3>Button</h3>
<b>Number of Batteries </b><input type="text" id="txt1"><br><br>
<table>
<tbody>
<tr>
<td><input type="radio" id="blue" name="Colour" value="blue">
<label for="blue" class="btnBlue"> Blue</label> </td>
<td><input type="radio" id="red" name="Colour" value="red">
<label for="red" class="btnRed"> Red</label></td>
<td><input type="radio" id="white" name="Colour" value="white">
<label for="white" class="btnWhite"> White</label> </td>
<td><input type="radio" id="yellow" name="Colour" value="yellow">
<label for="yellow" class="btnYellow"> Yellow</label></td>
<td><input type="radio" id="other" name="Colour" value="other" checked>
<label for="other" class="btnOther"> Other</label></td>
</tr>
<tr>
<td><input type="radio" id="hold" name="label" value="hold">
<label for="hold"> HOLD</label></td>
<td><input type="radio" id="abort" name="label" value="abort">
<label for="abort"> ABORT</label></td>
<td><input type="radio" id="detonate" name="label" value="detonate">
<label for="detonate"> DETONATE</label></td>
<td><input type="radio" id="other2" name="label" value="other2" checked>
<label for="other2"> Other</label></td>
</tr>
</tbody>
</table>
<br>
<span id="out"></span><br><br>
<b>Releasing a held button</b><br>
blue: 4<br>
yellow: 5<br>
else: 1<br>
<script>
var gui = document.getElementsByTagName("input");
var label = document.getElementsByTagName("label");
var txt1 = document.getElementById("txt1");
var out = document.getElementById("out");
txt1.addEventListener("keyup", change);
for (var i = 0; i < gui.length; i++) {
gui[i].addEventListener("change", change)
}
function change() {
for (var i = 0; i < label.length; i++) {
if (gui[label[i].getAttribute("for")].checked) {
label[i].classList.add("btnActive");
} else {
label[i].classList.remove("btnActive");
}
}
var done = false;
var txt = txt1.value;
var pos = "";
if (gui.blue.checked && gui.abort.checked) {
out.innerText = "Hold long";
done = true;
}
else if (gui.detonate.checked) {
if (!isInt(txt)) {
pos = "If there is more than 1 battery 'hold short' else ";
}
else if (Number.parseInt(txt) > 1) {
out.innerText = "Hold short";
done = true;
}
}
if (!done) {
if (gui.white.checked) {
pos += "if a label says 'CAR' 'hold long' else ";
}
if (!isInt(txt)) {
pos += "if a label says 'FRK' && there is more than 2 batteries 'hold short' else ";
}
else if (Number.parseInt(txt) > 2) {
pos += "if a label says 'FRK' 'hold short' else ";
}
if (gui.yellow.checked) {
out.innerText = pos + "hold long";
done = true;
}
if (!done) {
if (gui.red.checked && gui.hold.checked) {
out.innerText = pos + "hold short";
}
else {
out.innerText = pos + "hold long";
}
}
}
}
function isInt(s) {
return (Number.parseInt(s) > 0 || Number.parseInt(s) <= 0);
}
change();
</script>
</body>
</html>