From 422989bebc28004c61b460017c6ad480581779de Mon Sep 17 00:00:00 2001 From: ajuvercr Date: Sat, 21 Mar 2020 16:29:30 +0100 Subject: [PATCH] add shortcut keys --- mapbuilder/script.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mapbuilder/script.js b/mapbuilder/script.js index bcb4fe9..874534a 100644 --- a/mapbuilder/script.js +++ b/mapbuilder/script.js @@ -152,6 +152,7 @@ } const createColourButtons = () => { + const colourSecectors = []; COLOURS.forEach((colour, i) => { $colourButtonWrapper = document.querySelector(".colourButtonWrapper"); $button = document.createElement("input"); @@ -160,6 +161,9 @@ $button.classList.add("colourButton"); $button.type = "radio"; $button.value = i; + + colourSecectors.push($button); + $checkmark = document.createElement("span"); $checkmark.classList.add("colourButtonCheckmark"); $checkmark.classList.add("colourButton_"+colour); @@ -169,6 +173,14 @@ $container.append($checkmark); $colourButtonWrapper.append($container); }) + + document.addEventListener("keyup", (e) => { + var key = event.key || event.keyCode; + try { + colourSecectors[parseInt(key) - 1].checked = true; + } catch (_) { + } + }); } const handleChangeAmountOfSquares = e => {