From 39c939ebaf2683b4167ab65eb9cfdc202f90a35e Mon Sep 17 00:00:00 2001
From: Catalin Mititiuc
Date: Wed, 7 Aug 2024 11:03:14 -0700
Subject: Extract reveal record logic into a function
---
src/modules/record_sheet.js | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
(limited to 'src')
diff --git a/src/modules/record_sheet.js b/src/modules/record_sheet.js
index 841a693..8caf395 100644
--- a/src/modules/record_sheet.js
+++ b/src/modules/record_sheet.js
@@ -252,14 +252,7 @@ function clear() {
//document.querySelector('#defender-record .name').textContent = 'defender';
}
-function select(data) {
- const record = data && getRecord(data);
- const isSelected = record?.classList.contains('selected');
-
- deselect();
-
- if (isSelected || !data) return;
-
+function reveal(record) {
const currentSquadView = document.querySelector(`#record-sheet #${record.dataset.allegiance}-record .records-header .squad-number text`);
const records = document.querySelector(`#record-sheet #${record.dataset.allegiance}-record .records`);
const target = records.querySelector(`.squad-${record.dataset.squad}`);
@@ -302,10 +295,20 @@ function select(data) {
if (currentSquad !== target)
showSquad(currentSquad, target, direction);
- else {
- record.classList.add('selected');
+ else
record.scrollIntoView({ behavior: 'smooth' });
- }
+}
+
+function select(data) {
+ const record = data && getRecord(data);
+ const isSelected = record?.classList.contains('selected');
+
+ deselect();
+
+ if (isSelected || !data) return;
+
+ reveal(record);
+ record.classList.add('selected');
}
function endMove() {
--
cgit v1.2.3