This commit is contained in:
Florine W. Dekker 2019-06-10 01:15:12 +02:00
parent e7fe9a9254
commit 77ef279b7f
Signed by: FWDekker
GPG Key ID: B1B567AF58D6EE0F
1 changed files with 21 additions and 17 deletions

View File

@ -79,6 +79,8 @@
///
//////
const $ = query => document.querySelector(query);
const doAfterLoad = fun => {
const oldOnLoad = window.onload || (() => {
});
@ -126,15 +128,17 @@
// Functions
inputTable.getTable = () => document.querySelector("#dieSettings tbody");
inputTable.getTable = () => $("#dieSettings tbody");
inputTable.dieRowCount = () => inputTable.getTable().querySelectorAll(".dieEyes").length;
inputTable.highestDieRowIndex = () => {
const table = inputTable.getTable();
let highestDieRowIndex = -1;
iterateNodeList(table.getElementsByTagName("tr"), (node) => {
if (!isNaN(node.dataset.index))
highestDieRowIndex = Math.max(highestDieRowIndex, node.dataset.index);
if ("index" in node.dataset)
highestDieRowIndex = Math.max(highestDieRowIndex, +node.dataset.index);
});
return highestDieRowIndex;
@ -146,8 +150,8 @@
input.id = className + index;
input.className = className;
input.type = "number";
input.min = 1;
input.step = 1;
input.min = "1";
input.step = "1";
input.value = value;
input.addEventListener("keypress", (e) => {
if (e.key === "Enter")
@ -171,7 +175,7 @@
const table = inputTable.getTable();
const newIndex = inputTable.highestDieRowIndex() + 1;
const row = table.insertRow(newIndex);
const row = table.insertRow(inputTable.dieRowCount());
row.dataset.index = newIndex;
row.insertCell().appendChild(createNumberInput(newIndex, "dieEyes", 6));
@ -204,11 +208,11 @@
// Handlers
document.getElementById("addDieRowButton").onclick = inputTable.addDieRow;
$("#addDieRowButton").onclick = inputTable.addDieRow;
// Init
doAfterLoad(() => document.getElementById("addDieRowButton").click());
doAfterLoad(() => $("#addDieRowButton").click());
//////
@ -265,11 +269,11 @@
// Handlers
document.getElementById("submit").onclick = outputChart.updateProbGraph;
$("#submit").onclick = outputChart.updateProbGraph;
// Init
const ctx = document.getElementById("probChart").getContext("2d");
const ctx = $("#probChart").getContext("2d");
const probChart = new Chart(ctx, {
type: "line",
data: {},
@ -288,7 +292,7 @@
}
});
doAfterLoad(() => document.getElementById("submit").click());
doAfterLoad(() => $("#submit").click());
</script>
</body>
</html>