Fix squad reveal/select bug
This commit is contained in:
parent
b14c070373
commit
518693844d
@ -293,14 +293,6 @@ function getRecord({ dataset: { allegiance: al, number: n, squad: s }}) {
|
||||
return document.querySelector(selector);
|
||||
}
|
||||
|
||||
function deselect() {
|
||||
const selected = getSelected();
|
||||
|
||||
if (selected) {
|
||||
selected.classList.remove('selected');
|
||||
}
|
||||
}
|
||||
|
||||
function clear() {
|
||||
document.querySelectorAll('#record-sheet > *').forEach(el => {
|
||||
//el.querySelectorAll('.squad-number').forEach(sn => sn.remove());
|
||||
@ -338,13 +330,13 @@ function reveal(record) {
|
||||
// transformation. ScrollTo seems to create enough delay.
|
||||
toSquad.style.display = 'block';
|
||||
records.scrollTo(0, 0);
|
||||
|
||||
if (toSquad[`${direction}ElementSibling`] && toSquad !== target) {
|
||||
showSquad(toSquad, target, direction);
|
||||
} else {
|
||||
toSquad.style.transform = 'translateX(0)';
|
||||
|
||||
toSquad.addEventListener('transitionend', e => {
|
||||
record.classList.add('selected');
|
||||
record.scrollIntoView({ behavior: 'smooth' });
|
||||
}, { once: true });
|
||||
}
|
||||
@ -359,6 +351,12 @@ function reveal(record) {
|
||||
record.scrollIntoView({ behavior: 'smooth' });
|
||||
}
|
||||
|
||||
function deselect() {
|
||||
const selected = getSelected();
|
||||
|
||||
if (selected) selected.classList.remove('selected');
|
||||
}
|
||||
|
||||
function select(data, opts) {
|
||||
const record = data && getRecord(data);
|
||||
const isSelected = record?.classList.contains('selected');
|
||||
@ -367,8 +365,8 @@ function select(data, opts) {
|
||||
|
||||
if (isSelected || !data) return;
|
||||
|
||||
if (opts?.revealRecord) reveal(record);
|
||||
record.classList.add('selected');
|
||||
if (opts?.revealRecord) reveal(record);
|
||||
}
|
||||
|
||||
function endMove() {
|
||||
@ -379,9 +377,11 @@ function endMove() {
|
||||
const index = [...list].findIndex(s => s === selected);
|
||||
const next = list.length > 1 ? list[(index + 1) % list.length] : null;
|
||||
selected.classList.toggle('movement-ended');
|
||||
deselect();
|
||||
|
||||
if (next) Observable.notify('select', next, { revealCounter: true, revealRecord: true });
|
||||
if (next)
|
||||
Observable.notify('select', next, { revealCounter: true, revealRecord: true });
|
||||
else
|
||||
deselect();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user