diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2026-08-05 11:58:50 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2026-08-05 11:59:56 +0200 |
| commit | d35e03f0b07d1af3fecd51cd4ca42a76c300db23 (patch) | |
| tree | 92562e06ade3a2ac30e5ce39b8442d980b2fad08 /src/selection.js | |
| parent | 6c2bffd297bdfaf4e95a8f0620cf0349d3d3bb78 (diff) | |
| download | bycs-sol-d35e03f0b07d1af3fecd51cd4ca42a76c300db23.tar.gz bycs-sol-d35e03f0b07d1af3fecd51cd4ca42a76c300db23.zip | |
format: run prettier
Diffstat (limited to 'src/selection.js')
| -rw-r--r-- | src/selection.js | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/src/selection.js b/src/selection.js index bfaebc0..b7968af 100644 --- a/src/selection.js +++ b/src/selection.js @@ -27,7 +27,7 @@ async function initSelection(idPrefix, fetchCandidates, fmtCandidate, onSelectio let currentFocus = -1; let visibleItems = []; function setActive() { - visibleItems.forEach(item => item.classList.remove("active")); + visibleItems.forEach((item) => item.classList.remove("active")); if (currentFocus >= 0 && visibleItems[currentFocus]) { visibleItems[currentFocus].classList.add("active"); } @@ -37,11 +37,11 @@ async function initSelection(idPrefix, fetchCandidates, fmtCandidate, onSelectio const item = document.createElement("li"); item.candidate = candidate; item.innerHTML = fmtCandidate(candidate); - item.style.display = 'none'; + item.style.display = "none"; - item.addEventListener('click', function() { + item.addEventListener("click", function () { sel.value = ""; - sel.dispatchEvent(new Event('keyup')); + sel.dispatchEvent(new Event("keyup")); onSelection(candidate); }); @@ -49,9 +49,8 @@ async function initSelection(idPrefix, fetchCandidates, fmtCandidate, onSelectio items.push(item); } - sel.addEventListener('keyup', function(e) { - if ((["ArrowDown", "ArrowUp", "Enter"]).includes(e.key)) - return; + sel.addEventListener("keyup", function (e) { + if (["ArrowDown", "ArrowUp", "Enter"].includes(e.key)) return; const filter = sel.value.toLowerCase(); visibleItems = []; @@ -63,10 +62,10 @@ async function initSelection(idPrefix, fetchCandidates, fmtCandidate, onSelectio visibleItems.push(item); // Highlight matched text - const regex = new RegExp(`(${filter})`, 'gi'); + const regex = new RegExp(`(${filter})`, "gi"); item.innerHTML = item.textContent.replace( regex, - "<u class='student-selection-list-highlight'>$1</u>" + "<u class='student-selection-list-highlight'>$1</u>", ); } else { item.style.display = "none"; @@ -82,26 +81,23 @@ async function initSelection(idPrefix, fetchCandidates, fmtCandidate, onSelectio noResults.style.display = visibleItems.length || filter === "" ? "none" : "block"; }); - clearBtn.addEventListener('click', function() { + clearBtn.addEventListener("click", function () { sel.value = ""; - sel.dispatchEvent(new Event('keyup')); // reset list + sel.dispatchEvent(new Event("keyup")); // reset list sel.focus(); }); - sel.addEventListener('keydown', function(e) { + sel.addEventListener("keydown", function (e) { if (e.key === "ArrowDown" || e.key === "ArrowUp") { - if(e.key === "ArrowDown") - currentFocus = (currentFocus + 1) % visibleItems.length; - else - currentFocus = (currentFocus - 1 + visibleItems.length) % visibleItems.length; + if (e.key === "ArrowDown") currentFocus = (currentFocus + 1) % visibleItems.length; + else currentFocus = (currentFocus - 1 + visibleItems.length) % visibleItems.length; setActive(); e.preventDefault(); } else if (e.key === "Enter") { if (currentFocus > -1 && visibleItems[currentFocus]) { - const visibleItem = visibleItems[currentFocus]; sel.value = ""; - sel.dispatchEvent(new Event('keyup')); + sel.dispatchEvent(new Event("keyup")); onSelection(visibleItem.candidate); } e.preventDefault(); |
