Skip to content

Commit

Permalink
Merge branch 'feat/calculator' into feat/repo-homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
pricebenjamin committed Feb 25, 2024
2 parents 97776e2 + d913baf commit 5b34c6e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions 005-calculator/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ document.addEventListener('DOMContentLoaded', () => {
appRoot.addEventListener('click', clickHandler);
document.addEventListener('keydown', keyboardHandler);
document.addEventListener('keydown', simulateHover);
document.addEventListener('keyup', simulateHover);

function clickHandler(event) {
const target = event.target;
Expand All @@ -24,14 +23,20 @@ document.addEventListener('DOMContentLoaded', () => {
btn.click();
}

const buttonTimers = {};
const SIMULATED_HOVER_DELAY_MS = 100;

function simulateHover(event) {
const btn = buttonFilter(event);
if (!btn) return;
if (event.type == 'keydown') {
btn.classList.add('hover');
} else if (event.type == 'keyup') {
btn.classList.remove('hover');

btn.classList.add('hover');
if (buttonTimers[event.key]) {
clearTimeout(buttonTimers[event.key]);
}
buttonTimers[event.key] = setTimeout(() => {
btn.classList.remove('hover');
}, SIMULATED_HOVER_DELAY_MS);
}

function buttonFilter(event) {
Expand Down

0 comments on commit 5b34c6e

Please sign in to comment.