Improved shortcut handling
This commit is contained in:
parent
69a911e957
commit
e80a9b89c9
|
@ -1,19 +1,32 @@
|
|||
var checkedGroups = 0;
|
||||
var checkedGroups = [1,2,3,4,5];
|
||||
var countdownActive = false;
|
||||
|
||||
function monitorRadio() {
|
||||
document.querySelectorAll('input[type="radio"]').forEach(function (el) {
|
||||
el.addEventListener('change', incCounter, { once: true });
|
||||
el.addEventListener('change', removeId, { once: true });
|
||||
});
|
||||
}
|
||||
|
||||
function incCounter() {
|
||||
checkedGroups++;
|
||||
function removeId(e) {
|
||||
if (e) {
|
||||
value = e.target.id.charAt(1);
|
||||
} else {
|
||||
value = checkedGroups[0];
|
||||
}
|
||||
checkedGroups = checkedGroups.filter(function(item) {
|
||||
return item != value;
|
||||
})
|
||||
}
|
||||
|
||||
function checkCount() {
|
||||
if (checkedGroups === 5) {
|
||||
countdown();
|
||||
if (checkedGroups.length == 0) {
|
||||
if (countdownActive == false) {
|
||||
countdown();
|
||||
}
|
||||
countdownActive = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
window.addEventListener("keydown", function (event) {
|
||||
|
@ -21,18 +34,22 @@ window.addEventListener("keydown", function (event) {
|
|||
return;
|
||||
}
|
||||
|
||||
checkCount();
|
||||
if (checkCount()) {
|
||||
return;
|
||||
};
|
||||
|
||||
switch (event.key) {
|
||||
case "a":
|
||||
checkedGroups++;
|
||||
getid = 'a'+checkedGroups;
|
||||
value = checkedGroups[0];
|
||||
removeId();
|
||||
getid = 'a'+value;
|
||||
document.getElementById(getid).checked = true;
|
||||
checkCount();
|
||||
break;
|
||||
case "b":
|
||||
checkedGroups++;
|
||||
getid = 'b'+checkedGroups;
|
||||
value = checkedGroups[0];
|
||||
removeId();
|
||||
getid = 'b'+value;
|
||||
document.getElementById(getid).checked = true;
|
||||
checkCount();
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue