11import "whatwg-fetch" ;
22import { buttonEnabled , buttonLoading } from "../../libs/formHelpers" ;
33
4- const showEl = ( el : HTMLElement ) => el . classList . remove ( "u-hide" ) ;
5- const hideEl = ( el : HTMLElement ) => el . classList . add ( "u-hide" ) ;
4+ const showEl = ( el : HTMLElement ) : void => {
5+ el . classList . remove ( "u-hide" ) ;
6+ } ;
7+
8+ const hideEl = ( el : HTMLElement ) : void => {
9+ el . classList . add ( "u-hide" ) ;
10+ } ;
11+
12+ function initForm ( modal : HTMLElement ) : void {
13+ buttonEnabled ( modal . querySelector ( "button[type=submit]" ) ! , "Submit report" ) ;
14+
15+ showEl ( modal . querySelector ( ".js-report-snap-form" ) ! ) ;
16+ hideEl ( modal . querySelector ( ".js-report-snap-success" ) ! ) ;
17+ hideEl ( modal . querySelector ( ".js-report-snap-error" ) ! ) ;
18+ }
619
720function toggleModal ( modal : HTMLElement , show ?: boolean ) : void {
821 if ( typeof show === "undefined" ) {
@@ -17,27 +30,16 @@ function toggleModal(modal: HTMLElement, show?: boolean): void {
1730 }
1831}
1932
20- function initForm ( modal : HTMLElement ) : void {
21- buttonEnabled (
22- modal . querySelector ( "button[type=submit]" ) as HTMLButtonElement ,
23- "Submit report" ,
24- ) ;
25-
26- showEl ( modal . querySelector ( ".js-report-snap-form" ) as HTMLElement ) ;
27- hideEl ( modal . querySelector ( ".js-report-snap-success" ) as HTMLElement ) ;
28- hideEl ( modal . querySelector ( ".js-report-snap-error" ) as HTMLElement ) ;
29- }
30-
3133function showSuccess ( modal : HTMLElement ) : void {
32- hideEl ( modal . querySelector ( ".js-report-snap-form" ) as HTMLElement ) ;
33- showEl ( modal . querySelector ( ".js-report-snap-success" ) as HTMLElement ) ;
34- hideEl ( modal . querySelector ( ".js-report-snap-error" ) as HTMLElement ) ;
34+ hideEl ( modal . querySelector ( ".js-report-snap-form" ) ! ) ;
35+ showEl ( modal . querySelector ( ".js-report-snap-success" ) ! ) ;
36+ hideEl ( modal . querySelector ( ".js-report-snap-error" ) ! ) ;
3537}
3638
3739function showError ( modal : HTMLElement ) : void {
38- hideEl ( modal . querySelector ( ".js-report-snap-form" ) as HTMLElement ) ;
39- hideEl ( modal . querySelector ( ".js-report-snap-success" ) as HTMLElement ) ;
40- showEl ( modal . querySelector ( ".js-report-snap-error" ) as HTMLElement ) ;
40+ hideEl ( modal . querySelector ( ".js-report-snap-form" ) ! ) ;
41+ hideEl ( modal . querySelector ( ".js-report-snap-success" ) ! ) ;
42+ showEl ( modal . querySelector ( ".js-report-snap-error" ) ! ) ;
4143}
4244
4345export default function initReportSnap (
@@ -72,14 +74,11 @@ export default function initReportSnap(
7274 reportForm . addEventListener ( "submit" , async ( e ) => {
7375 e . preventDefault ( ) ;
7476 buttonLoading (
75- reportForm . querySelector ( "button[type=submit]" ) as HTMLButtonElement ,
77+ reportForm . querySelector ( "button[type=submit]" ) ! ,
7678 "Submitting…" ,
7779 ) ;
7880
79- if (
80- honeypotField . checked ||
81- ( commentField . value && commentField . value . includes ( "http" ) )
82- ) {
81+ if ( honeypotField . checked || commentField ?. value ?. includes ( "http" ) ) {
8382 showSuccess ( modal ) ;
8483 return ;
8584 }
@@ -111,7 +110,7 @@ export default function initReportSnap(
111110
112111 // close modal on ESC
113112 window . addEventListener ( "keyup" , ( event ) => {
114- if ( event . keyCode === 27 ) {
113+ if ( event . key === "Escape" ) {
115114 toggleModal ( modal , false ) ;
116115 }
117116 } ) ;
0 commit comments