index : btroops | |
Virtual board game-aid for BattleTroops, an infantry combat simulator wargame published by FASA in 1989. |
aboutsummaryrefslogtreecommitdiff |
diff options
author | Catalin Mititiuc <webdevcat@proton.me> | 2024-08-05 17:12:39 -0700 |
---|---|---|
committer | Catalin Mititiuc <webdevcat@proton.me> | 2024-08-05 17:12:39 -0700 |
commit | c6cdbcf492a1830bcc16259d018980072485e4fb (patch) | |
tree | 0c871162f56938f68df87568a1d232d25fadd314 | |
parent | 26771e4832da8134262f0e6d09b9d8d715493269 (diff) |
Don't throw error when no squads to view
-rw-r--r-- | src/index.js | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/src/index.js b/src/index.js index decc0f8..88cfced 100644 --- a/src/index.js +++ b/src/index.js @@ -263,34 +263,34 @@ document.querySelectorAll('.view-squad').forEach(b => b.addEventListener('click' const currentSquad = b.closest('.records-header').querySelector('.squad-number text'); const currentSquadContainer = b.closest('[id$="-record"]').querySelector(`.records > .squad-${currentSquad.textContent}`); - if (b.value === 'next') { - //const toSquad = currentSquadContainer.nextElementSibling || b.closest('[id$="-record"]').querySelector('.records > :first-child'); - const toSquad = currentSquadContainer.nextElementSibling; - if (!toSquad) return; - currentSquad.textContent = +toSquad.className.match(/\d+/); - - currentSquadContainer.addEventListener('transitionend', e => { - console.log('transitionend', 'current', currentSquadContainer, 'next', toSquad); - currentSquadContainer.style.display = 'none'; - toSquad.style.display = 'block'; - b.closest('[id$="-record"]').querySelector('.records').scrollTo(0, 0); - toSquad.style.transform = 'translateX(0)'; - }, { once: true }); - - currentSquadContainer.style.transform = 'translateX(-100%)'; - } else { - const toSquad = currentSquadContainer.previousElementSibling; - if (!toSquad) return; - currentSquad.textContent = +toSquad.className.match(/\d+/); - - currentSquadContainer.addEventListener('transitionend', e => { - currentSquadContainer.style.display = 'none'; - toSquad.style.display = 'block'; - b.closest('[id$="-record"]').querySelector('.records').scrollTo(0, 0); - toSquad.style.transform = 'translateX(0)'; - }, { once: true }); - - currentSquadContainer.style.transform = 'translateX(100%)'; + if (currentSquadContainer) { + if (b.value === 'next') { + const toSquad = currentSquadContainer.nextElementSibling; + if (!toSquad) return; + currentSquad.textContent = +toSquad.className.match(/\d+/); + + currentSquadContainer.addEventListener('transitionend', e => { + currentSquadContainer.style.display = 'none'; + toSquad.style.display = 'block'; + b.closest('[id$="-record"]').querySelector('.records').scrollTo(0, 0); + toSquad.style.transform = 'translateX(0)'; + }, { once: true }); + + currentSquadContainer.style.transform = 'translateX(-100%)'; + } else { + const toSquad = currentSquadContainer.previousElementSibling; + if (!toSquad) return; + currentSquad.textContent = +toSquad.className.match(/\d+/); + + currentSquadContainer.addEventListener('transitionend', e => { + currentSquadContainer.style.display = 'none'; + toSquad.style.display = 'block'; + b.closest('[id$="-record"]').querySelector('.records').scrollTo(0, 0); + toSquad.style.transform = 'translateX(0)'; + }, { once: true }); + + currentSquadContainer.style.transform = 'translateX(100%)'; + } } })); |