Moves where call to localInitGame is done, auto adds tabindexes to game and x-button and anchors as well as event listener to handle space or enter when they are selected via keyboard
Moves where call to localInitGame is done, auto adds tabindexes to game and x-button and anchors as well as event listener to handle space or enter when they are selected via keyboard
diff --git a/js/game.js b/js/game.js
index 5b32ca1..da66bd6 100644
--- a/js/game.js
+++ b/js/game.js
@@ -397,7 +397,9 @@ function addListenersAnchors(anchors)
for (const anchor of anchors) {
let hash = anchor.getAttribute("href");
if (hash && hash[0] == "#") {
- anchor.addEventListener('click', (event) => {
+ anchor.innerHTML = "<span tabindex='0'>" +anchor.innerHTML +
+ "</span>";
+ let handle = (event) => {
if (!anchor.classList.contains('disabled')) {
game.takeTurn(hash);
if (game.has_nav_bar && call_toggle) {
@@ -408,7 +410,13 @@ function addListenersAnchors(anchors)
if (window.location.hash) {
delete window.location.hash;
}
+ };
+ anchor.addEventListener('keydown', (event) => {
+ if (event.code == 'Enter' || event.code == 'Space') {
+ handle(event);
+ }
});
+ anchor.addEventListener('click', (event) => handle(event));
}
}
}
@@ -1615,6 +1623,13 @@ class Game
async function initGame()
{
game = new Game();
+ /*
+ Any game specific customizations are assumed to be in the function
+ localInitGame if it exists
+ */
+ if (typeof localInitGame == 'function') {
+ localInitGame();
+ }
let use_session = false;
if (sessionStorage["current" + game.id]) {
use_session = true;
@@ -1626,11 +1641,4 @@ async function initGame()
game.takeTurn("");
game.clearHistory();
game.initializeScreen();
- /*
- Any game specific customizations are assumed to be in the function
- localInitGame if it exists
- */
- if (typeof localInitGame == 'function') {
- localInitGame();
- }
}