From af674545ffb9965a55d1bc1b692c27bc982fe540 Mon Sep 17 00:00:00 2001 From: Hendrik Huyskens Date: Thu, 23 May 2024 14:46:25 +0200 Subject: [PATCH] Make linter happy --- digiplan/static/js/elements.js | 2 +- digiplan/static/js/scenarios.js | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/digiplan/static/js/elements.js b/digiplan/static/js/elements.js index 726cc264..61584e7d 100644 --- a/digiplan/static/js/elements.js +++ b/digiplan/static/js/elements.js @@ -112,4 +112,4 @@ document.querySelectorAll('.layer__switch').forEach(checkbox => { checkbox.addEventListener('change', event => { event.target.setAttribute('aria-checked', event.target.checked.toString()); }); -}); \ No newline at end of file +}); diff --git a/digiplan/static/js/scenarios.js b/digiplan/static/js/scenarios.js index dd5bae79..0e051dbd 100644 --- a/digiplan/static/js/scenarios.js +++ b/digiplan/static/js/scenarios.js @@ -17,11 +17,7 @@ const scenarioPanels = ["panelCard1", "panelCard2", "panelCard3"]; for (const scenarioPanel of scenarioPanels) { const panelElement = document.getElementById(scenarioPanel); panelElement.addEventListener("click", scenarioCardClicked); - panelElement.addEventListener("keydown", function (event) { - if (event.key === "Enter" || event.key === " ") { - scenarioCardClicked(event); - } - }); + panelElement.addEventListener("keydown", scenarioCardClicked); } Array.from(document.getElementsByClassName("scenarios__btn")).forEach( @@ -80,9 +76,11 @@ function selectScenario(msg) { } function scenarioCardClicked(event) { - event.preventDefault(); // Prevent default action for keyboard events - const scenarioCardNumber = parseInt(event.currentTarget.id.slice(-1)); - selectScenarioCard(scenarioCardNumber); + if (event.key === "Enter" || event.key === " " || event.type === "click") { + event.preventDefault(); // Prevent default action for keyboard events + const scenarioCardNumber = parseInt(event.currentTarget.id.slice(-1)); + selectScenarioCard(scenarioCardNumber); + } } function selectScenarioCard(scenarioCardNumber) {