recipe-site/assets/script.js

42 lines
1.2 KiB
JavaScript

window.onload = function () {
Array.from(dgcn('method-checkbox')).forEach(checkbox => {
// uncheck all the checkboxes every time the page is reloaded
checkbox.checked = false;
checkbox.onclick = function () {
let num = parseInt(this.dataset.number);
let prefix = this.parentElement.parentElement.dataset.cbPrefix;
let max = this.parentElement.parentElement.children.length;
if (this.checked) {
// check everything before this - if you've done step 6, you've done steps 1-5
for (i = num - 1; i > 0; i--) {
cb = dgel(`${prefix}-${i}`);
cb.checked = true;
cb.parentElement.classList.add("checked");
}
} else {
// uncheck everything after this - you can't have done step 8 if you haven't done step 4
console.log(num + 1);
for (i = num + 1; i <= max; i++) {
cb = dgel(`${prefix}-${i}`);
cb.checked = false;
cb.parentElement.classList.remove("checked");
}
}
this.parentElement.classList.toggle("checked");
}
})
}
function dgcn(cn) {
return document.getElementsByClassName(cn);
}
function dgel(id) {
return document.getElementById(id);
}
function subrecipe_toggle(id) {
dgel(id).classList.toggle("open");
}