recipe-site/assets/script.js

38 lines
1 KiB
JavaScript
Raw Normal View History

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--) {
dgel(`${prefix}-${i}`).checked = true;
}
} 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++) {
console.log(i);
dgel(`${prefix}-${i}`).checked = false;
}
}
}
})
}
function dgcn(cn) {
return document.getElementsByClassName(cn);
}
2020-03-01 06:52:39 +00:00
function dgel(id) {
return document.getElementById(id);
}
function subrecipe_toggle(id) {
dgel(id).classList.toggle("open");
}