Skip to content

Commit cbb64ae

Browse files
committed
testing
1 parent 1710403 commit cbb64ae

File tree

1 file changed

+44
-44
lines changed

1 file changed

+44
-44
lines changed

docs/index.html

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,19 @@ <h1 id="title">Mercury 2025</h1>
223223
<script>
224224
class Question {
225225

226-
constructor(id, title, resetType, pageName) {
226+
constructor(id, title, defaultValue, resetType, pageName) {
227227
this.id = id;
228228
this.title = title;
229229
this.pageName = pageName;
230230
this.element = null;
231231
this.resetType = resetType;
232+
this.defaultValue = defaultValue;
232233
}
233234

234235
set value(newValue) {
235236
this.element.value = newValue;
237+
localStorage.setItem(this.id, newValue);
238+
this.updateOutlineColor();
236239
}
237240

238241
get value() {
@@ -252,7 +255,7 @@ <h1 id="title">Mercury 2025</h1>
252255
container.id = this.id;
253256
container.classList.add('question');
254257
const label = document.createElement('label');
255-
label.innerHTML = this.title;
258+
label.textContent = this.title;
256259
label.style.marginRight = '4%';
257260
container.appendChild(label);
258261
return container;
@@ -268,19 +271,19 @@ <h1 id="title">Mercury 2025</h1>
268271
}
269272

270273
clear() {
271-
this.value = '';
272-
}
273-
274-
updateOutlineColor() {
275-
this.outlineColor = this.isValid() ? COLORS.VALID : COLORS.INVALID;
274+
this.value = this.defaultValue;
276275
}
277276

278-
addListeners() {
277+
addListener() {
279278
this.element.addEventListener('input', () => {
280279
localStorage.setItem(this.id, this.value);
281280
this.updateOutlineColor();
282281
});
283282
}
283+
284+
updateOutlineColor() {
285+
this.outlineColor = this.isValid() ? COLORS.VALID : COLORS.INVALID;
286+
}
284287
}
285288

286289
class LineQuestion extends Question {
@@ -299,7 +302,7 @@ <h1 id="title">Mercury 2025</h1>
299302
input.maxLength = 20;
300303
container.appendChild(input);
301304
this.element = input;
302-
this.addListeners()
305+
this.addListener();
303306
return container;
304307
}
305308
}
@@ -312,30 +315,30 @@ <h1 id="title">Mercury 2025</h1>
312315
}
313316

314317
clear() {
315-
this.value = ' ';
318+
this.value = this.defaultValue || '';
316319
}
317320

318321
createElement() {
319322
const container = super.createElement();
320323
container.classList.add('text_box_question');
321324
const textarea = document.createElement('textarea');
322325
textarea.maxLength = 150;
323-
textarea.value = ' ';
324326
container.appendChild(textarea);
325327
this.element = textarea;
326-
this.addListeners()
328+
this.addListener();
327329
return container;
328330
}
329331
}
330332

331333
class SelectQuestion extends Question {
332334
static type = 'select';
333335

334-
constructor(id, title, resetType, pageName, choices) {
335-
super(id, title, resetType, pageName);
336+
constructor(id, title, defaultValue, resetType, pageName, choices) {
337+
super(id, title, defaultValue, resetType, pageName);
336338
this.choices = choices;
337339
this._value = null;
338340
this.buttonMap = new Map();
341+
this._value = localStorage.getItem(this.id) || defaultValue;
339342
}
340343

341344
set value(newValue) {
@@ -378,8 +381,8 @@ <h1 id="title">Mercury 2025</h1>
378381
class NumberFromChoicesQuestion extends Question {
379382
static type = 'numberFromChoices';
380383

381-
constructor(id, title, resetType, pageName, choices) {
382-
super(id, title, resetType, pageName);
384+
constructor(id, title, defaultValue, resetType, pageName, choices) {
385+
super(id, title, defaultValue, resetType, pageName);
383386
this.choices = choices;
384387
}
385388

@@ -410,7 +413,7 @@ <h1 id="title">Mercury 2025</h1>
410413
container.appendChild(input);
411414
container.appendChild(datalist);
412415
this.element = input;
413-
this.addListeners()
416+
this.addListener();
414417
return container;
415418
}
416419
}
@@ -423,15 +426,17 @@ <h1 id="title">Mercury 2025</h1>
423426
}
424427

425428
clear() {
426-
this.value = 0;
429+
this.value = this.defaultValue || 0;
427430
}
428431

429432
set value(newValue) {
430-
this.element.innerText = String(newValue);
433+
this.element.textContent = String(newValue);
434+
localStorage.setItem(this.id, newValue);
435+
this.updateOutlineColor();
431436
}
432437

433438
get value() {
434-
return parseInt(this.element.innerText);
439+
return parseInt(this.element.textContent);
435440
}
436441

437442
createElement() {
@@ -441,31 +446,26 @@ <h1 id="title">Mercury 2025</h1>
441446
const numberLabel = document.createElement('label');
442447
numberLabel.classList.add('number_question_number');
443448
numberLabel.type = 'number';
444-
numberLabel.innerText = '0';
445449
this.element = numberLabel;
446450

447451
const decrementButton = document.createElement('button');
448452
decrementButton.textContent = '-';
449453
decrementButton.onclick = () => {
450-
if (this.value <= 0) return;
454+
if (this.value <= 0 || this.value <= this.defaultValue) return;
451455
this.value = this.value - 1;
452-
this.element.dispatchEvent(new Event('input')); // Trigger change event
453456
};
454457

455458
const incrementButton = document.createElement('button');
456459
incrementButton.textContent = "+";
457460
incrementButton.onclick = () => {
458461
this.value = this.value + 1;
459-
this.element.dispatchEvent(new Event('input')); // Trigger change event
460462
};
461463

462464
const buttonContainer = document.createElement('div');
463465
buttonContainer.appendChild(decrementButton);
464466
buttonContainer.appendChild(numberLabel);
465467
buttonContainer.appendChild(incrementButton);
466468
container.appendChild(buttonContainer);
467-
468-
this.addListeners()
469469
return container;
470470
}
471471
}
@@ -584,7 +584,7 @@ <h1 id="title">Mercury 2025</h1>
584584
function renderAbsoluteNavigationButtons(container) {
585585
pageMaps.forEach(page => {
586586
const button = document.createElement('button');
587-
button.innerHTML = page.name;
587+
button.textContent = page.name;
588588
button.classList.add('absolute_navigation');
589589
button.addEventListener('click', () => displayPage(page.name));
590590
container.appendChild(button);
@@ -598,7 +598,7 @@ <h1 id="title">Mercury 2025</h1>
598598
}
599599
window.scrollTo({ top: 0, behavior: 'smooth' });
600600
updateButtons(pageName);
601-
htmlGlobals.titleLabel.innerHTML = pageName;
601+
htmlGlobals.titleLabel.textContent = pageName;
602602
localStorage.setItem('currentPage', pageName);
603603
}
604604

@@ -617,7 +617,7 @@ <h1 id="title">Mercury 2025</h1>
617617
nextButton.onclick = pageIndex + 1 < pageAmount ? () => displayPage(pageMaps[pageIndex + 1].name) : null;
618618

619619
for (const pageButton of absoluteNavigationElements) {
620-
pageButton.style.fontWeight = pageButton.innerHTML === pageName ? 'bold' : 'normal';
620+
pageButton.style.fontWeight = pageButton.textContent === pageName ? 'bold' : 'normal';
621621
}
622622
}
623623

@@ -630,7 +630,7 @@ <h1 id="title">Mercury 2025</h1>
630630
if (typeof question === 'string') {
631631
// titles
632632
const label = document.createElement('label');
633-
label.innerHTML = question;
633+
label.textContent = question;
634634
label.style.borderBottom = '0.1em solid gray';
635635
pageContainer.appendChild(label);
636636
} else {
@@ -640,6 +640,7 @@ <h1 id="title">Mercury 2025</h1>
640640

641641
const savedValue = localStorage.getItem(question.id);
642642
if (savedValue) questionObject.value = savedValue;
643+
else questionObject.clear();
643644
questionObject.updateOutlineColor();
644645

645646
questionObjects.push(questionObject); // Add to the page's question list
@@ -651,17 +652,18 @@ <h1 id="title">Mercury 2025</h1>
651652

652653
function createQuestion(question, pageName) {
653654
const resetType = question.resetType || RESET_TYPES.CLEAR;
655+
const defaultValue = question.defaultValue || '';
654656
switch (question.type) {
655657
case LineQuestion.type:
656-
return new LineQuestion(question.id, question.title, resetType, pageName);
658+
return new LineQuestion(question.id, question.title, defaultValue, resetType, pageName);
657659
case TextBoxQuestion.type:
658-
return new TextBoxQuestion(question.id, question.title, resetType, pageName);
660+
return new TextBoxQuestion(question.id, question.title, defaultValue, resetType, pageName);
659661
case NumberQuestion.type:
660-
return new NumberQuestion(question.id, question.title, resetType, pageName);
662+
return new NumberQuestion(question.id, question.title, defaultValue, resetType, pageName);
661663
case SelectQuestion.type:
662-
return new SelectQuestion(question.id, question.title, resetType, pageName, question.choices);
664+
return new SelectQuestion(question.id, question.title, defaultValue, resetType, pageName, question.choices);
663665
case NumberFromChoicesQuestion.type:
664-
return new NumberFromChoicesQuestion(question.id, question.title, resetType, pageName, question.choices);
666+
return new NumberFromChoicesQuestion(question.id, question.title, defaultValue, resetType, pageName, question.choices);
665667
}
666668
}
667669

@@ -672,12 +674,10 @@ <h1 id="title">Mercury 2025</h1>
672674
let lastTouchEnd = 0;
673675
document.addEventListener('touchend', function (event) {
674676
let now = Date.now();
675-
676677
// Allow normal clicks on buttons
677678
if (event.target.tagName === 'BUTTON' || event.target.closest('[role="button"]')) {
678679
return;
679680
}
680-
681681
// Block double-tap zoom for everything else
682682
if (now - lastTouchEnd <= 300) {
683683
event.preventDefault();
@@ -751,9 +751,9 @@ <h1 id="title">Mercury 2025</h1>
751751
"General Info",
752752
{"id": "scouter_name", "title": "Scouter name", "resetType": RESET_TYPES.KEEP, "type": LineQuestion.type},
753753
{"id": "game_type", "title": "Game Type", "resetType": RESET_TYPES.KEEP, "choices": ["Practice", "Qualifications", "Playoffs"], "type": SelectQuestion.type},
754-
{"id": "game_number", "title": "Game Number", "separateLine": true,"resetType": RESET_TYPES.INCREASE, "type": NumberQuestion.type}, "Team Info",
755-
{"id": "team_number", "title": "Team Number", "choices": ALL_TEAMS, "separateLine": true, "type": NumberFromChoicesQuestion.type},
756-
{"id": "alliance_color", "title": "Alliance", "resetType": RESET_TYPES.KEEP, "choices": ["Red", "Blue"], "separateLine": true, "type": SelectQuestion.type}
754+
{"id": "game_number", "title": "Game Number", "defaultValue": 1, "resetType": RESET_TYPES.INCREASE, "type": NumberQuestion.type}, "Team Info",
755+
{"id": "team_number", "title": "Team Number", "choices": ALL_TEAMS, "type": NumberFromChoicesQuestion.type},
756+
{"id": "alliance_color", "title": "Alliance", "resetType": RESET_TYPES.KEEP, "choices": ["Red", "Blue"], "type": SelectQuestion.type}
757757
]
758758
},
759759
{
@@ -769,11 +769,11 @@ <h1 id="title">Mercury 2025</h1>
769769
{"id": "auto_high_algae", "title": "High", "type": NumberQuestion.type},
770770
{"id": "auto_low_algae", "title": "Low", "type": NumberQuestion.type},
771771
"Algae:",
772-
{"id": "auto_robot_algae_throws", "title": "Robot Throws to Net", "separateLine": true, "type": NumberQuestion.type},
773-
{"id": "auto_algae_inserts", "title": "Algae Processor Inserts", "separateLine": true, "type": NumberQuestion.type},
772+
{"id": "auto_robot_algae_throws", "title": "Robot Throws to Net", "type": NumberQuestion.type},
773+
{"id": "auto_algae_inserts", "title": "Algae Processor Inserts", "type": NumberQuestion.type},
774774
"Human Player:",
775-
{"id": "auto_human_player_algae_successful_throws", "title": "Successful Net Throws", "separateLine": true, "type": NumberQuestion.type},
776-
{"id": "auto_human_player_algae_failed_throws", "title": "Failed Net Throws", "separateLine": true, "type": NumberQuestion.type},
775+
{"id": "auto_human_player_algae_successful_throws", "title": "Successful Net Throws", "type": NumberQuestion.type},
776+
{"id": "auto_human_player_algae_failed_throws", "title": "Failed Net Throws", "type": NumberQuestion.type},
777777
]
778778
},
779779
{

0 commit comments

Comments
 (0)