@@ -223,16 +223,19 @@ <h1 id="title">Mercury 2025</h1>
223
223
< script >
224
224
class Question {
225
225
226
- constructor ( id , title , resetType , pageName ) {
226
+ constructor ( id , title , defaultValue , resetType , pageName ) {
227
227
this . id = id ;
228
228
this . title = title ;
229
229
this . pageName = pageName ;
230
230
this . element = null ;
231
231
this . resetType = resetType ;
232
+ this . defaultValue = defaultValue ;
232
233
}
233
234
234
235
set value ( newValue ) {
235
236
this . element . value = newValue ;
237
+ localStorage . setItem ( this . id , newValue ) ;
238
+ this . updateOutlineColor ( ) ;
236
239
}
237
240
238
241
get value ( ) {
@@ -252,7 +255,7 @@ <h1 id="title">Mercury 2025</h1>
252
255
container . id = this . id ;
253
256
container . classList . add ( 'question' ) ;
254
257
const label = document . createElement ( 'label' ) ;
255
- label . innerHTML = this . title ;
258
+ label . textContent = this . title ;
256
259
label . style . marginRight = '4%' ;
257
260
container . appendChild ( label ) ;
258
261
return container ;
@@ -268,19 +271,19 @@ <h1 id="title">Mercury 2025</h1>
268
271
}
269
272
270
273
clear ( ) {
271
- this . value = '' ;
272
- }
273
-
274
- updateOutlineColor ( ) {
275
- this . outlineColor = this . isValid ( ) ? COLORS . VALID : COLORS . INVALID ;
274
+ this . value = this . defaultValue ;
276
275
}
277
276
278
- addListeners ( ) {
277
+ addListener ( ) {
279
278
this . element . addEventListener ( 'input' , ( ) => {
280
279
localStorage . setItem ( this . id , this . value ) ;
281
280
this . updateOutlineColor ( ) ;
282
281
} ) ;
283
282
}
283
+
284
+ updateOutlineColor ( ) {
285
+ this . outlineColor = this . isValid ( ) ? COLORS . VALID : COLORS . INVALID ;
286
+ }
284
287
}
285
288
286
289
class LineQuestion extends Question {
@@ -299,7 +302,7 @@ <h1 id="title">Mercury 2025</h1>
299
302
input . maxLength = 20 ;
300
303
container . appendChild ( input ) ;
301
304
this . element = input ;
302
- this . addListeners ( )
305
+ this . addListener ( ) ;
303
306
return container ;
304
307
}
305
308
}
@@ -312,30 +315,30 @@ <h1 id="title">Mercury 2025</h1>
312
315
}
313
316
314
317
clear ( ) {
315
- this . value = ' ';
318
+ this . value = this . defaultValue || ' ';
316
319
}
317
320
318
321
createElement ( ) {
319
322
const container = super . createElement ( ) ;
320
323
container . classList . add ( 'text_box_question' ) ;
321
324
const textarea = document . createElement ( 'textarea' ) ;
322
325
textarea . maxLength = 150 ;
323
- textarea . value = ' ' ;
324
326
container . appendChild ( textarea ) ;
325
327
this . element = textarea ;
326
- this . addListeners ( )
328
+ this . addListener ( ) ;
327
329
return container ;
328
330
}
329
331
}
330
332
331
333
class SelectQuestion extends Question {
332
334
static type = 'select' ;
333
335
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 ) ;
336
338
this . choices = choices ;
337
339
this . _value = null ;
338
340
this . buttonMap = new Map ( ) ;
341
+ this . _value = localStorage . getItem ( this . id ) || defaultValue ;
339
342
}
340
343
341
344
set value ( newValue ) {
@@ -378,8 +381,8 @@ <h1 id="title">Mercury 2025</h1>
378
381
class NumberFromChoicesQuestion extends Question {
379
382
static type = 'numberFromChoices' ;
380
383
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 ) ;
383
386
this . choices = choices ;
384
387
}
385
388
@@ -410,7 +413,7 @@ <h1 id="title">Mercury 2025</h1>
410
413
container . appendChild ( input ) ;
411
414
container . appendChild ( datalist ) ;
412
415
this . element = input ;
413
- this . addListeners ( )
416
+ this . addListener ( ) ;
414
417
return container ;
415
418
}
416
419
}
@@ -423,15 +426,17 @@ <h1 id="title">Mercury 2025</h1>
423
426
}
424
427
425
428
clear ( ) {
426
- this . value = 0 ;
429
+ this . value = this . defaultValue || 0 ;
427
430
}
428
431
429
432
set value ( newValue ) {
430
- this . element . innerText = String ( newValue ) ;
433
+ this . element . textContent = String ( newValue ) ;
434
+ localStorage . setItem ( this . id , newValue ) ;
435
+ this . updateOutlineColor ( ) ;
431
436
}
432
437
433
438
get value ( ) {
434
- return parseInt ( this . element . innerText ) ;
439
+ return parseInt ( this . element . textContent ) ;
435
440
}
436
441
437
442
createElement ( ) {
@@ -441,31 +446,26 @@ <h1 id="title">Mercury 2025</h1>
441
446
const numberLabel = document . createElement ( 'label' ) ;
442
447
numberLabel . classList . add ( 'number_question_number' ) ;
443
448
numberLabel . type = 'number' ;
444
- numberLabel . innerText = '0' ;
445
449
this . element = numberLabel ;
446
450
447
451
const decrementButton = document . createElement ( 'button' ) ;
448
452
decrementButton . textContent = '-' ;
449
453
decrementButton . onclick = ( ) => {
450
- if ( this . value <= 0 ) return ;
454
+ if ( this . value <= 0 || this . value <= this . defaultValue ) return ;
451
455
this . value = this . value - 1 ;
452
- this . element . dispatchEvent ( new Event ( 'input' ) ) ; // Trigger change event
453
456
} ;
454
457
455
458
const incrementButton = document . createElement ( 'button' ) ;
456
459
incrementButton . textContent = "+" ;
457
460
incrementButton . onclick = ( ) => {
458
461
this . value = this . value + 1 ;
459
- this . element . dispatchEvent ( new Event ( 'input' ) ) ; // Trigger change event
460
462
} ;
461
463
462
464
const buttonContainer = document . createElement ( 'div' ) ;
463
465
buttonContainer . appendChild ( decrementButton ) ;
464
466
buttonContainer . appendChild ( numberLabel ) ;
465
467
buttonContainer . appendChild ( incrementButton ) ;
466
468
container . appendChild ( buttonContainer ) ;
467
-
468
- this . addListeners ( )
469
469
return container ;
470
470
}
471
471
}
@@ -584,7 +584,7 @@ <h1 id="title">Mercury 2025</h1>
584
584
function renderAbsoluteNavigationButtons ( container ) {
585
585
pageMaps . forEach ( page => {
586
586
const button = document . createElement ( 'button' ) ;
587
- button . innerHTML = page . name ;
587
+ button . textContent = page . name ;
588
588
button . classList . add ( 'absolute_navigation' ) ;
589
589
button . addEventListener ( 'click' , ( ) => displayPage ( page . name ) ) ;
590
590
container . appendChild ( button ) ;
@@ -598,7 +598,7 @@ <h1 id="title">Mercury 2025</h1>
598
598
}
599
599
window . scrollTo ( { top : 0 , behavior : 'smooth' } ) ;
600
600
updateButtons ( pageName ) ;
601
- htmlGlobals . titleLabel . innerHTML = pageName ;
601
+ htmlGlobals . titleLabel . textContent = pageName ;
602
602
localStorage . setItem ( 'currentPage' , pageName ) ;
603
603
}
604
604
@@ -617,7 +617,7 @@ <h1 id="title">Mercury 2025</h1>
617
617
nextButton . onclick = pageIndex + 1 < pageAmount ? ( ) => displayPage ( pageMaps [ pageIndex + 1 ] . name ) : null ;
618
618
619
619
for ( const pageButton of absoluteNavigationElements ) {
620
- pageButton . style . fontWeight = pageButton . innerHTML === pageName ? 'bold' : 'normal' ;
620
+ pageButton . style . fontWeight = pageButton . textContent === pageName ? 'bold' : 'normal' ;
621
621
}
622
622
}
623
623
@@ -630,7 +630,7 @@ <h1 id="title">Mercury 2025</h1>
630
630
if ( typeof question === 'string' ) {
631
631
// titles
632
632
const label = document . createElement ( 'label' ) ;
633
- label . innerHTML = question ;
633
+ label . textContent = question ;
634
634
label . style . borderBottom = '0.1em solid gray' ;
635
635
pageContainer . appendChild ( label ) ;
636
636
} else {
@@ -640,6 +640,7 @@ <h1 id="title">Mercury 2025</h1>
640
640
641
641
const savedValue = localStorage . getItem ( question . id ) ;
642
642
if ( savedValue ) questionObject . value = savedValue ;
643
+ else questionObject . clear ( ) ;
643
644
questionObject . updateOutlineColor ( ) ;
644
645
645
646
questionObjects . push ( questionObject ) ; // Add to the page's question list
@@ -651,17 +652,18 @@ <h1 id="title">Mercury 2025</h1>
651
652
652
653
function createQuestion ( question , pageName ) {
653
654
const resetType = question . resetType || RESET_TYPES . CLEAR ;
655
+ const defaultValue = question . defaultValue || '' ;
654
656
switch ( question . type ) {
655
657
case LineQuestion . type :
656
- return new LineQuestion ( question . id , question . title , resetType , pageName ) ;
658
+ return new LineQuestion ( question . id , question . title , defaultValue , resetType , pageName ) ;
657
659
case TextBoxQuestion . type :
658
- return new TextBoxQuestion ( question . id , question . title , resetType , pageName ) ;
660
+ return new TextBoxQuestion ( question . id , question . title , defaultValue , resetType , pageName ) ;
659
661
case NumberQuestion . type :
660
- return new NumberQuestion ( question . id , question . title , resetType , pageName ) ;
662
+ return new NumberQuestion ( question . id , question . title , defaultValue , resetType , pageName ) ;
661
663
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 ) ;
663
665
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 ) ;
665
667
}
666
668
}
667
669
@@ -672,12 +674,10 @@ <h1 id="title">Mercury 2025</h1>
672
674
let lastTouchEnd = 0 ;
673
675
document . addEventListener ( 'touchend' , function ( event ) {
674
676
let now = Date . now ( ) ;
675
-
676
677
// Allow normal clicks on buttons
677
678
if ( event . target . tagName === 'BUTTON' || event . target . closest ( '[role="button"]' ) ) {
678
679
return ;
679
680
}
680
-
681
681
// Block double-tap zoom for everything else
682
682
if ( now - lastTouchEnd <= 300 ) {
683
683
event . preventDefault ( ) ;
@@ -751,9 +751,9 @@ <h1 id="title">Mercury 2025</h1>
751
751
"General Info" ,
752
752
{ "id" : "scouter_name" , "title" : "Scouter name" , "resetType" : RESET_TYPES . KEEP , "type" : LineQuestion . type } ,
753
753
{ "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 }
757
757
]
758
758
} ,
759
759
{
@@ -769,11 +769,11 @@ <h1 id="title">Mercury 2025</h1>
769
769
{ "id" : "auto_high_algae" , "title" : "High" , "type" : NumberQuestion . type } ,
770
770
{ "id" : "auto_low_algae" , "title" : "Low" , "type" : NumberQuestion . type } ,
771
771
"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 } ,
774
774
"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 } ,
777
777
]
778
778
} ,
779
779
{
0 commit comments