Put penalties functions in their own file again
This commit is contained in:
parent
78bb2099cc
commit
593ddedd9d
|
@ -69,12 +69,14 @@
|
|||
<p>
|
||||
<span id="period" onclick="handle(event);">--:--</span>
|
||||
<br>
|
||||
<span id="timeouts-a" onclick="handle(event);">0</span>
|
||||
<span id="periodtext" onclick="handle(event);">-</span>
|
||||
<span id="timeouts-b" onclick="handle(event);">0</span>
|
||||
</p>
|
||||
<p>
|
||||
<span id="timeouts-a" onclick="handle(event);">0</span>
|
||||
<span id="jammer-a" onclick="handle(event);">★</span>
|
||||
<span id="jamtext">-</span>
|
||||
<span id="timeouts-b" onclick="handle(event);">0</span>
|
||||
<span id="jammer-b" onclick="handle(event);">★</span>
|
||||
<br>
|
||||
<span id="jam" onclick="handle(event);">-:--.--</span>
|
||||
</p>
|
||||
|
|
|
@ -0,0 +1,183 @@
|
|||
/***********************************
|
||||
* Penalties
|
||||
*/
|
||||
function penalties (team) {
|
||||
var table = document.getElementById("penalties-" + team);
|
||||
|
||||
var minors = table.getElementsByClassName("minors")[0];
|
||||
var majors = table.getElementsByClassName("majors")[0];
|
||||
var sk8ers = table.getElementsByClassName("sk8ers")[0];
|
||||
|
||||
var mindiv = minors.getElementsByTagName("div");
|
||||
var majdiv = majors.getElementsByTagName("div");
|
||||
var sk8div = sk8ers.getElementsByTagName("div");
|
||||
|
||||
var ret = [];
|
||||
|
||||
for (var i = 0; i < 20; i += 1) {
|
||||
ret.push([sk8div[i].text,
|
||||
mindiv[i].value || 0,
|
||||
majdiv[i].value || 0]);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
function penalties_save () {
|
||||
var ls = localStorage || {};
|
||||
|
||||
var name_a = document.getElementById("name-a").innerHTML;
|
||||
var name_b = document.getElementById("name-b").innerHTML;
|
||||
|
||||
var pen_a = JSON.stringify(penalties("a"));
|
||||
var pen_b = JSON.stringify(penalties("b"));
|
||||
|
||||
ls["rdsb_penalties_a"] = pen_a;
|
||||
ls["rdsb_penalties_b"] = pen_b;
|
||||
|
||||
ls["rdsb_roster " + name_a] = pen_a;
|
||||
ls["rdsb_roster " + name_b] = pen_b;
|
||||
}
|
||||
|
||||
function penalties_setdiv (div, value) {
|
||||
if (div.text == undefined) {
|
||||
div.value = value;
|
||||
div.style.height = (value||0) + "em";
|
||||
div.innerHTML = value?value:"";
|
||||
} else {
|
||||
div.text = value;
|
||||
div.innerHTML = value?"":"•";
|
||||
for (var i in value) {
|
||||
var c = value[i];
|
||||
// XXX: use CSS "text-wrap: unrestricted" when supported
|
||||
div.innerHTML += c + " ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function penalties_load (team, values) {
|
||||
var table = document.getElementById("penalties-" + team);
|
||||
|
||||
var minors = table.getElementsByClassName("minors")[0];
|
||||
var majors = table.getElementsByClassName("majors")[0];
|
||||
var sk8ers = table.getElementsByClassName("sk8ers")[0];
|
||||
|
||||
var mindiv = minors.getElementsByTagName("div");
|
||||
var majdiv = majors.getElementsByTagName("div");
|
||||
var sk8div = sk8ers.getElementsByTagName("div");
|
||||
|
||||
for (var i = 0; i < values.length; i += 1) {
|
||||
penalties_setdiv(sk8div[i], values[i][0]);
|
||||
penalties_setdiv(mindiv[i], values[i][1]);
|
||||
penalties_setdiv(majdiv[i], values[i][2]);
|
||||
}
|
||||
}
|
||||
|
||||
function penalties_setTeamName (team, name) {
|
||||
var ls = localStorage || {};
|
||||
var roster_in = ls["rdsb_roster " + name];
|
||||
var roster_out = [];
|
||||
|
||||
if (roster_in) {
|
||||
roster_in = JSON.parse(roster_in);
|
||||
}
|
||||
|
||||
for (var i = 0; i < 20; i += 1) {
|
||||
if (! roster_in) {
|
||||
roster_out.push(["", 0, 0]);
|
||||
} else {
|
||||
roster_out.push([roster_in[i][0], 0, 0])
|
||||
}
|
||||
}
|
||||
penalties_load(team, roster_out);
|
||||
}
|
||||
|
||||
function penalties_click (event) {
|
||||
var element = event.currentTarget;
|
||||
var pops = element.parentNode;
|
||||
var div = element.getElementsByTagName("div")[0];
|
||||
var inc = event.shiftKey?-1:1;
|
||||
var val;
|
||||
|
||||
if (pops.className == "minors") {
|
||||
val = ((div.value || 0) + inc + 4) % 4;
|
||||
if ((inc == 1) && (val == 0)) {
|
||||
var majdiv = div.majdiv;
|
||||
|
||||
penalties_setdiv(majdiv, ((majdiv.value || 0) + 1) % 9);
|
||||
}
|
||||
} else if (pops.className == "majors") {
|
||||
val = ((div.value || 0) + inc + 9) % 9;
|
||||
} else {
|
||||
val = prompt("Enter skater number", div.text);
|
||||
}
|
||||
|
||||
if (val != undefined) {
|
||||
penalties_setdiv(div, val);
|
||||
penalties_save();
|
||||
}
|
||||
}
|
||||
|
||||
// Remove penalties area if there are no players set
|
||||
function penalties_duck () {
|
||||
var pen = document.getElementById("penalties");
|
||||
var a = penalties("a");
|
||||
var b = penalties("b");
|
||||
|
||||
for (var i = 0; i < 20; i += 1) {
|
||||
if (a[i][0] || b[i][0]) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
pen.style.display = "none";
|
||||
}
|
||||
|
||||
function penalties_init () {
|
||||
var ls = localStorage || {};
|
||||
|
||||
// Populate ALL THREE ROWS AT ONCE because I'm crazy like that.
|
||||
for (var j = 0; j < 2; j += 1) {
|
||||
var team = (j==0)?"a":"b";
|
||||
|
||||
var table = document.getElementById("penalties-" + team);
|
||||
var minors = table.getElementsByClassName("minors")[0];
|
||||
var majors = table.getElementsByClassName("majors")[0];
|
||||
var sk8ers = table.getElementsByClassName("sk8ers")[0];
|
||||
|
||||
for (var i = 0; i < 20; i += 1) {
|
||||
var td;
|
||||
var div;
|
||||
|
||||
var majdiv = document.createElement("div");
|
||||
td = document.createElement("td");
|
||||
td.onclick = penalties_click;
|
||||
td.appendChild(majdiv);
|
||||
majors.appendChild(td);
|
||||
|
||||
|
||||
td = document.createElement("td");
|
||||
div = document.createElement("div");
|
||||
div.majdiv = majdiv;
|
||||
td.onclick = penalties_click;
|
||||
td.appendChild(div);
|
||||
minors.appendChild(td);
|
||||
|
||||
|
||||
div = document.createElement("div");
|
||||
div.text = "";
|
||||
div.appendChild(document.createTextNode("•"));
|
||||
td = document.createElement("td");
|
||||
td.onclick = penalties_click;
|
||||
td.appendChild(div);
|
||||
sk8ers.appendChild(td);
|
||||
}
|
||||
}
|
||||
|
||||
if (ls.rdsb_penalties_a) {
|
||||
penalties_load("a", JSON.parse(ls.rdsb_penalties_a));
|
||||
}
|
||||
if (ls.rdsb_penalties_b) {
|
||||
penalties_load("b", JSON.parse(ls.rdsb_penalties_b));
|
||||
}
|
||||
}
|
|
@ -41,6 +41,7 @@
|
|||
<link rel="stylesheet" type="text/css" href="scoreboard.css">
|
||||
<script type="text/javascript" src="logos.js"></script>
|
||||
<script type="text/javascript" src="scoreboard.js"></script>
|
||||
<script type="text/javascript" src="penalties.js"></script>
|
||||
<script type="text/javascript">
|
||||
window.onkeypress = key;
|
||||
</script>
|
||||
|
|
193
scoreboard.js
193
scoreboard.js
|
@ -146,7 +146,7 @@ function transition(newstate) {
|
|||
return;
|
||||
}
|
||||
|
||||
if ((state == SETUP) && penalties_duck) {
|
||||
if ((state == SETUP) && window.penalties) {
|
||||
penalties_duck();
|
||||
}
|
||||
|
||||
|
@ -177,189 +177,6 @@ function transition(newstate) {
|
|||
e("jammer-b").className = "";
|
||||
}
|
||||
|
||||
/***********************************
|
||||
* Penalties
|
||||
*/
|
||||
function penalties (team) {
|
||||
var table = document.getElementById("penalties-" + team);
|
||||
|
||||
var minors = table.getElementsByClassName("minors")[0];
|
||||
var majors = table.getElementsByClassName("majors")[0];
|
||||
var sk8ers = table.getElementsByClassName("sk8ers")[0];
|
||||
|
||||
var mindiv = minors.getElementsByTagName("div");
|
||||
var majdiv = majors.getElementsByTagName("div");
|
||||
var sk8div = sk8ers.getElementsByTagName("div");
|
||||
|
||||
var ret = [];
|
||||
|
||||
for (var i = 0; i < 20; i += 1) {
|
||||
ret.push([sk8div[i].text,
|
||||
mindiv[i].value || 0,
|
||||
majdiv[i].value || 0]);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
function penalties_save () {
|
||||
var ls = localStorage || {};
|
||||
|
||||
var name_a = document.getElementById("name-a").innerHTML;
|
||||
var name_b = document.getElementById("name-b").innerHTML;
|
||||
|
||||
var pen_a = JSON.stringify(penalties("a"));
|
||||
var pen_b = JSON.stringify(penalties("b"));
|
||||
|
||||
ls["rdsb_penalties_a"] = pen_a;
|
||||
ls["rdsb_penalties_b"] = pen_b;
|
||||
|
||||
ls["rdsb_roster " + name_a] = pen_a;
|
||||
ls["rdsb_roster " + name_b] = pen_b;
|
||||
}
|
||||
|
||||
function penalties_setdiv (div, value) {
|
||||
if (div.text == undefined) {
|
||||
div.value = value;
|
||||
div.style.height = (value||0) + "em";
|
||||
div.innerHTML = value?value:"";
|
||||
} else {
|
||||
div.text = value;
|
||||
div.innerHTML = value?"":"•";
|
||||
for (var i in value) {
|
||||
var c = value[i];
|
||||
// XXX: use CSS "text-wrap: unrestricted" when supported
|
||||
div.innerHTML += c + " ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function penalties_load (team, values) {
|
||||
var table = document.getElementById("penalties-" + team);
|
||||
|
||||
var minors = table.getElementsByClassName("minors")[0];
|
||||
var majors = table.getElementsByClassName("majors")[0];
|
||||
var sk8ers = table.getElementsByClassName("sk8ers")[0];
|
||||
|
||||
var mindiv = minors.getElementsByTagName("div");
|
||||
var majdiv = majors.getElementsByTagName("div");
|
||||
var sk8div = sk8ers.getElementsByTagName("div");
|
||||
|
||||
for (var i = 0; i < values.length; i += 1) {
|
||||
penalties_setdiv(sk8div[i], values[i][0]);
|
||||
penalties_setdiv(mindiv[i], values[i][1]);
|
||||
penalties_setdiv(majdiv[i], values[i][2]);
|
||||
}
|
||||
}
|
||||
|
||||
function penalties_setTeamName (team, name) {
|
||||
var ls = localStorage || {};
|
||||
var roster_in = ls["rdsb_roster " + name];
|
||||
var roster_out = [];
|
||||
|
||||
if (roster_in) {
|
||||
roster_in = JSON.parse(roster_in);
|
||||
}
|
||||
|
||||
for (var i = 0; i < 20; i += 1) {
|
||||
if (! roster_in) {
|
||||
roster_out.push(["", 0, 0]);
|
||||
} else {
|
||||
roster_out.push([roster_in[i][0], 0, 0])
|
||||
}
|
||||
}
|
||||
penalties_load(team, roster_out);
|
||||
}
|
||||
|
||||
function penalties_click (event) {
|
||||
var element = event.currentTarget;
|
||||
var pops = element.parentNode;
|
||||
var div = element.getElementsByTagName("div")[0];
|
||||
var inc = event.shiftKey?-1:1;
|
||||
var val;
|
||||
|
||||
if (pops.className == "minors") {
|
||||
val = ((div.value || 0) + inc + 4) % 4;
|
||||
if ((inc == 1) && (val == 0)) {
|
||||
var majdiv = div.majdiv;
|
||||
|
||||
penalties_setdiv(majdiv, ((majdiv.value || 0) + 1) % 9);
|
||||
}
|
||||
} else if (pops.className == "majors") {
|
||||
val = ((div.value || 0) + inc + 9) % 9;
|
||||
} else {
|
||||
val = prompt("Enter skater number", div.text);
|
||||
}
|
||||
|
||||
if (val != undefined) {
|
||||
penalties_setdiv(div, val);
|
||||
penalties_save();
|
||||
}
|
||||
}
|
||||
|
||||
// Remove penalties area if there are no players set
|
||||
function penalties_duck () {
|
||||
var pen = document.getElementById("penalties");
|
||||
var a = penalties("a");
|
||||
var b = penalties("b");
|
||||
|
||||
for (var i = 0; i < 20; i += 1) {
|
||||
if (a[i][0] || b[i][0]) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
pen.style.display = "none";
|
||||
}
|
||||
|
||||
function penalties_init () {
|
||||
var ls = localStorage || {};
|
||||
|
||||
// Populate ALL THREE ROWS AT ONCE because I'm crazy like that.
|
||||
for (var j = 0; j < 2; j += 1) {
|
||||
var team = (j==0)?"a":"b";
|
||||
|
||||
var table = document.getElementById("penalties-" + team);
|
||||
var minors = table.getElementsByClassName("minors")[0];
|
||||
var majors = table.getElementsByClassName("majors")[0];
|
||||
var sk8ers = table.getElementsByClassName("sk8ers")[0];
|
||||
|
||||
for (var i = 0; i < 20; i += 1) {
|
||||
var td;
|
||||
var div;
|
||||
|
||||
var majdiv = document.createElement("div");
|
||||
td = document.createElement("td");
|
||||
td.onclick = penalties_click;
|
||||
td.appendChild(majdiv);
|
||||
majors.appendChild(td);
|
||||
|
||||
|
||||
td = document.createElement("td");
|
||||
div = document.createElement("div");
|
||||
div.majdiv = majdiv;
|
||||
td.onclick = penalties_click;
|
||||
td.appendChild(div);
|
||||
minors.appendChild(td);
|
||||
|
||||
|
||||
div = document.createElement("div");
|
||||
div.text = "";
|
||||
div.appendChild(document.createTextNode("•"));
|
||||
td = document.createElement("td");
|
||||
td.onclick = penalties_click;
|
||||
td.appendChild(div);
|
||||
sk8ers.appendChild(td);
|
||||
}
|
||||
}
|
||||
|
||||
if (ls.rdsb_penalties_a) {
|
||||
penalties_load("a", JSON.parse(ls.rdsb_penalties_a));
|
||||
}
|
||||
if (ls.rdsb_penalties_b) {
|
||||
penalties_load("b", JSON.parse(ls.rdsb_penalties_b));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***********************************
|
||||
|
@ -425,8 +242,10 @@ function handle(event) {
|
|||
if (tn) {
|
||||
tgt.innerHTML = tn;
|
||||
}
|
||||
if (window.penalties) {
|
||||
penalties_setTeamName(team, tn);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "logo-a":
|
||||
case "logo-b":
|
||||
|
@ -446,8 +265,10 @@ function handle(event) {
|
|||
e("name-" + team).innerHTML = t[0];
|
||||
tgt.src = "logos/" + t[1];
|
||||
|
||||
if (window.penalties) {
|
||||
penalties_setTeamName(team, t[0]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
score(team, -adj);
|
||||
}
|
||||
|
@ -616,7 +437,9 @@ function start() {
|
|||
save_itimer = setInterval(save, 1000);
|
||||
}
|
||||
|
||||
window.penalties_init();
|
||||
if (window.penalties) {
|
||||
penalties_init();
|
||||
}
|
||||
|
||||
e("periodtext").innerHTML = periodtext[period];
|
||||
e("jamtext").innerHTML = "Setup";
|
||||
|
|
Loading…
Reference in New Issue