Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/index.js')
-rw-r--r--src/index.js8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/index.js b/src/index.js
index 2cd2db6..2e2e306 100644
--- a/src/index.js
+++ b/src/index.js
@@ -145,7 +145,7 @@ async function load() {
document.querySelectorAll('.end-turn').forEach(el =>
el.addEventListener('click', ({ target: { dataset: { allegiance: opponent }}}) => {
const dataSelector = `[data-allegiance="${opponent}"]`,
- opponentRecords = Array.from(document.querySelectorAll(`.soldier-record${dataSelector}`)),
+ opponentRecords = Array.from(document.querySelectorAll(`.soldier-record${dataSelector}:not(.inactive)`)),
firstOpponentRecord = opponentRecords.sort((el1, el2) => el1.dataset.number > el2.dataset.number).at(0);
el.setAttribute('disabled', '');
@@ -154,7 +154,11 @@ document.querySelectorAll('.end-turn').forEach(el =>
clearMoveEndedIndicators(opponentRecords);
gameboard.clearFiringArcs(opponent);
- Observable.notify('select', firstOpponentRecord);
+
+ if (firstOpponentRecord) {
+ Observable.notify('select', firstOpponentRecord);
+ firstOpponentRecord.scrollIntoView({ behavior: 'smooth' });
+ }
})
);