chore: fixed auto play in leaderboard view
4be7a830
1 file(s) · +9 −2
| 210 | 210 | submitScore() |
|
| 211 | 211 | } |
|
| 212 | 212 | }) |
|
| 213 | + | // Prevent spacebar from natively activating buttons (which would restart the game) |
|
| 214 | + | actionBtn.addEventListener('keydown', (e) => { |
|
| 215 | + | if (e.key === ' ') { |
|
| 216 | + | e.preventDefault() |
|
| 217 | + | } |
|
| 218 | + | }) |
|
| 213 | 219 | ||
| 214 | 220 | // Leaderboard caching |
|
| 215 | 221 | const leaderboardCache = { |
|
| 311 | 317 | hideOverlay() |
|
| 312 | 318 | return |
|
| 313 | 319 | } |
|
| 314 | - | // Space/Up closes modal only if not in input field (must press Play Again to restart) |
|
| 315 | - | if (document.activeElement !== initialsInput && keycodes.JUMP[e.keyCode]) { |
|
| 320 | + | // Space/Up closes modal only if focus is outside the modal (must press Play Again to restart) |
|
| 321 | + | const modal = document.getElementById('score-modal') |
|
| 322 | + | if (!modal.contains(document.activeElement) && keycodes.JUMP[e.keyCode]) { |
|
| 316 | 323 | hideOverlay() |
|
| 317 | 324 | } |
|
| 318 | 325 | } |
|