]> gitweb.michael.orlitzky.com - charm-bypass.git/blob - index.html.in
index.html.in: reword the daily security code hint
[charm-bypass.git] / index.html.in
1 <!doctype html>
2 <html lang="en-US">
3 <head>
4 <meta charset="utf-8">
5 <meta name="viewport" content="width=device-width, initial-scale=1" />
6 <link rel="icon"
7 type="image/svg+xml"
8 href="data:image/svg+xml;base64,@FAVICON@" />
9
10 <title>
11 CharmBypass: it's transit equity y'all
12 </title>
13
14 <style>
15 body {
16 /* For consistency with the SVG */
17 font-family: sans-serif;
18 }
19
20 fieldset {
21 margin-top: 1em;
22 padding-top: 1em;
23 }
24
25 input[type=submit] {
26 margin-top: 1em;
27 margin-bottom: 1em;
28 }
29
30 legend {
31 font-weight: bold;
32 }
33
34 svg {
35 /* Set the height to 100% of the screen, which we'll keep; and the
36 * initial position to (0,0), which we're going to change
37 * every time the window is resized, because the exact amount
38 * that we have to slide the SVG to the left to get the ticket
39 * into the center will change. */
40 position: fixed;
41 top: 0;
42 left: 0;
43 height: 100%;
44
45 /* Hide everything by default. We only show it once the user has
46 * submitted the menu form */
47 display: none;
48 }
49
50 /* The blinking fade in/out animation for the ticket date and time */
51 @keyframes blink {
52 25% { opacity: 0.5; }
53 50% { opacity: 0; }
54 75% { opacity: 0.5; }
55 }
56
57 #tickettime, #ticketdate {
58 /* 300 two-second blinks is ten minutes */
59 animation: blink 2s linear 300;
60 }
61
62 /* Define, load, and specify the custom font we use for the ticket
63 * date, time, and service name. */
64 @font-face {
65 font-family: "CharmBypass Regular";
66 src:
67 url("data:font/woff2;base64,@CBPREGULAR@") format("woff2")
68 }
69
70 #origindest, #servicename, #tickettime, #ticketdate, #codetext, #zone {
71 font-family: "CharmBypass Regular", sans-serif;
72 }
73
74 @font-face {
75 font-family: "CharmBypass Bold";
76 src:
77 url("data:font/woff2;base64,@CBPBOLD@") format("woff2")
78 }
79
80 #serviceid {
81 font-family: "CharmBypass Bold", sans-serif;
82 }
83
84 /************************/
85 /* Scrolling animations */
86 /************************/
87
88 /* Bus */
89 @keyframes busroll {
90 from { transform: translateX(0%); }
91 to { transform: translateX(-100%); }
92 }
93
94 #bus {
95 animation: busroll 23s linear infinite;
96 }
97
98
99 /* Tram */
100 @keyframes tramroll {
101 from { transform: translateX(0%); }
102 to { transform: translateX(100%); }
103 }
104
105 #tram {
106 animation: tramroll 17s linear infinite;
107 }
108
109
110 /* Train */
111 @keyframes trainroll {
112 from { transform: translateX(0%); }
113 to { transform: translateX(100%); }
114 }
115
116 #train {
117 animation: trainroll 11s linear infinite;
118 }
119
120
121 /* Clouds */
122 @keyframes cloudsfloat {
123 from { transform: translateX(0%); }
124 to { transform: translateX(-50%); }
125 }
126
127 #clouds {
128 animation: cloudsfloat 40s linear infinite;
129 }
130
131 @keyframes cloudscopyfloat {
132 from { transform: translateX(0%); }
133 to { transform: translateX(-50%); }
134 }
135
136 #cloudscopy {
137 animation: cloudscopyfloat 40s linear infinite;
138 }
139
140
141 /* Trees */
142 @keyframes treespass {
143 from { transform: translateX(0%); }
144 to { transform: translateX(-50%); }
145 }
146
147 #trees {
148 /* The trees move a little faster than the clouds */
149 animation: treespass 30s linear infinite;
150 }
151
152 @keyframes treescopypass {
153 from { transform: translateX(0%); }
154 to { transform: translateX(-50%); }
155 }
156
157 #treescopy {
158 /* The trees move a little faster than the clouds */
159 animation: treescopypass 30s linear infinite;
160 }
161
162
163 /* City skyline */
164 @keyframes cityscroll {
165 from { transform: translateX(0%); }
166 to { transform: translateX(-50%); }
167 }
168
169 #city {
170 /* The city moves faster than the clouds but slower
171 * than the trees */
172 animation: cityscroll 35s linear infinite;
173 }
174
175 @keyframes citycopyscroll {
176 from { transform: translateX(0%); }
177 to { transform: translateX(-50%); }
178 }
179
180 #citycopy {
181 /* The city moves faster than the clouds but slower
182 * than the trees */
183 animation: citycopyscroll 35s linear infinite;
184 }
185 </style>
186 </head>
187
188 <body>
189 <div id="menu">
190 <h1>CharmBypass</h1>
191 <h2>it's transit equity y'all</h2>
192
193 <p>
194 <em>Hint:</em> If they start checking it, the daily security
195 code stays the same all day and is the same on a $2 bus ticket
196 as it is on a $9 MARC ticket. It's also the same on every phone.
197 </p>
198
199 <form>
200 <fieldset>
201 <legend>Local Bus, Light Rail, or Metro</legend>
202 <div>
203 <label for="code1">
204 Daily security code (optional):
205 </label>
206 <input id="code1"
207 name="code"
208 type="text"
209 size="2"
210 minlength="2"
211 maxlength="2"
212 pattern="[a-zA-Z0-9]*" />
213 </div>
214 <input type="hidden" name="servicename" value="BaltimoreLink" />
215 <input type="submit" name="go" value="Generate Ticket" />
216 </fieldset>
217 </form>
218 <form>
219 <fieldset>
220 <legend>Commuter Bus</legend>
221 <input type="hidden" name="serviceid" value="R" />
222 <input type="hidden" name="servicename" value="Commuter Bus" />
223
224 <div>
225 <label for="code2">
226 Daily security code (optional):
227 </label>
228 <input id="code2"
229 name="code"
230 type="text"
231 size="2"
232 minlength="2"
233 maxlength="2"
234 pattern="[a-zA-Z0-9]*" />
235 </div>
236
237 <p>Zone:</p>
238 <div>
239 <input type="radio" required
240 name="zone"
241 id="zone1"
242 value="Zone 1" />
243 <label for="zone1">Zone 1</label>
244 </div>
245 <div>
246 <input type="radio" required
247 name="zone"
248 id="zone2"
249 value="Zone 2" />
250 <label for="zone2">Zone 2</label>
251 </div>
252 <div>
253 <input type="radio" required checked
254 name="zone"
255 id="zone3"
256 value="Zone 3" />
257 <label for="zone3">Zone 3</label>
258 </div>
259 <div>
260 <input type="radio" required
261 name="zone"
262 id="zone4"
263 value="Zone 4" />
264 <label for="zone4">Zone 4</label>
265 </div>
266 <div>
267 <input type="radio" required
268 name="zone"
269 id="zone5"
270 value="Zone 5" />
271 <label for="zone5">Zone 5</label>
272 </div>
273
274 <input type="submit" name="go" value="Generate Ticket" />
275 </fieldset>
276 </form>
277 <form>
278 <fieldset>
279 <legend>MARC Train</legend>
280
281 <div>
282 <label for="code3">
283 Daily security code (optional):
284 </label>
285 <input id="code3"
286 name="code"
287 type="text"
288 size="2"
289 minlength="2"
290 maxlength="2"
291 pattern="[a-zA-Z0-9]*" />
292 </div>
293
294 <p>Origin:</p>
295 <div>
296 <input type="radio" required checked
297 name="origin"
298 id="origin1"
299 value="BAL" />
300 <label for="origin1">Baltimore/Penn (Penn Line)</label>
301 </div>
302 <div>
303 <input type="radio" required
304 name="origin"
305 id="origin2"
306 value="BCA" />
307 <label for="origin2">Baltimore/Camden (Camden Line)</label>
308 </div>
309 <div>
310 <input type="radio" required
311 name="origin"
312 id="origin3"
313 value="BWE" />
314 <label for="origin3">Bowie State (Penn Line)</label>
315 </div>
316 <div>
317 <input type="radio" required
318 name="origin"
319 id="origin4"
320 value="BWI" />
321 <label for="origin4">BWI Airport (Penn Line)</label>
322 </div>
323 <div>
324 <input type="radio" required
325 name="origin"
326 id="origin5"
327 value="CPK" />
328 <label for="origin5">College Park (Camden Line)</label>
329 </div>
330 <div>
331 <input type="radio" required
332 name="origin"
333 id="origin6"
334 value="SEB" />
335 <label for="origin6">Seabrook (Penn Line)</label>
336 </div>
337 <div>
338 <input type="radio" required
339 name="origin"
340 id="origin7"
341 value="WAS" />
342 <label for="origin7">Washington D.C.</label>
343 </div>
344 <div>
345 <input type="radio" required
346 name="origin"
347 id="origin8"
348 value="WBL" />
349 <label for="origin8">West Baltimore (Penn Line)</label>
350 </div>
351
352 <p>Destination:</p>
353 <div>
354 <input type="radio" required
355 name="destination"
356 id="destination1"
357 value="BAL" />
358 <label for="destination1">Baltimore/Penn (Penn Line)</label>
359 </div>
360 <div>
361 <input type="radio" required
362 name="destination"
363 id="destination2"
364 value="BCA" />
365 <label for="destination2">Baltimore/Camden (Camden Line)</label>
366 </div>
367 <div>
368 <input type="radio" required
369 name="destination"
370 id="destination3"
371 value="BWE" />
372 <label for="destination3">Bowie State (Penn Line)</label>
373 </div>
374 <div>
375 <input type="radio" required
376 name="destination"
377 id="destination4"
378 value="BWI" />
379 <label for="destination4">BWI Airport (Penn Line)</label>
380 </div>
381 <div>
382 <input type="radio" required
383 name="destination"
384 id="destination5"
385 value="CPK" />
386 <label for="destination5">College Park (Camden Line)</label>
387 </div>
388 <div>
389 <input type="radio" required
390 name="destination"
391 id="destination6"
392 value="SEB" />
393 <label for="destination6">Seabrook (Penn Line)</label>
394 </div>
395 <div>
396 <input type="radio" required checked
397 name="destination"
398 id="destination7"
399 value="WAS" />
400 <label for="destination7">Washington D.C.</label>
401 </div>
402 <div>
403 <input type="radio" required
404 name="destination"
405 id="destination8"
406 value="WBL" />
407 <label for="destination8">West Baltimore (Penn Line)</label>
408 </div>
409
410 <input type="hidden" name="serviceid" value="R" />
411 <input type="hidden" name="servicename" value="MARC Train" />
412 <input type="submit" name="go" value="Generate Ticket" />
413 </fieldset>
414 </form>
415 </div>
416
417 @SVGDATA@
418
419 <script>
420
421 /**
422 * Center the ticket within the browser by translating the SVG
423 * until the ticket and the viewport centerlines coincide.
424 */
425 function center_ticket() {
426 /* We're relying on the SVG being the full height of the
427 * viewport already, and on the aspect ratio being
428 * preserved. First, find the center of the ticket. */
429 const r = document.getElementById("ticket").getBoundingClientRect();
430 const c = r.left + (r.width / 2);
431
432 /* That's the center-line of the ticket. We want to move it to
433 * the center-line of the viewport. */
434 const vc = document.documentElement.clientWidth / 2;
435
436 /* This is how much we need to translate the SVG */
437 const hdelta = vc - c;
438
439 /* But before we can set the absolute left-coordinate of the
440 * SVG, we need to know where it is now. Note: without the
441 * "px" this doesn't default to pixels like CSS does. */
442 const svg = document.querySelector("svg");
443 svg.style.left = (svg.getBoundingClientRect().left + hdelta) + "px";
444 }
445
446
447 /**
448 * Set the service identifier from the querystring if it's there.
449 * Otherwise, leave it at the default of "F".
450 */
451 function set_service_id() {
452 const sid = document.getElementById("serviceid");
453
454 /* Get the "serviceid" from the querystring if it's there */
455 const params = new URLSearchParams(document.location.search);
456 if (params.get("serviceid")) {
457 sid.textContent = params.get("serviceid");
458 }
459 }
460
461
462 /**
463 * Set the service name from the querystring if it's there.
464 * Otherwise, leave it at the default of "BaltimoreLink".
465 */
466 function set_service_name() {
467 const sid = document.getElementById("servicename");
468
469 /* Get the "servicename" from the querystring if it's there */
470 const params = new URLSearchParams(document.location.search);
471 if (params.get("servicename")) {
472 sid.textContent = params.get("servicename");
473 }
474 }
475
476
477 /**
478 * Set the zone from the given "zone" parameter and then unhide it.
479 */
480 function set_zone(zone) {
481 const z = document.getElementById("zone");
482
483 z.textContent = zone;
484 z.style.display = "block"; /* hidden by default */
485 }
486
487
488 /**
489 * Resize the ticket background based on the service name.
490 * The BaltimoreLink, Commuter Bus, and MARC Train tickets
491 * are all different heights and are arranged vertically a
492 * bit different.
493 *
494 * Rather than design three completelty separate tickets and
495 * then have to keep track of which one we're using, I have
496 * instead decided to use one ticket and to reposition it
497 * on-the-fly based on the service name. This is necessarily
498 * a bit ugly because it involves a lot of magic numbers that
499 * can only be explained if you open up inkscape with a CharmPass
500 * screenshot to see where things belong and how to get them there.
501 *
502 * The SVG was designed with BaltimoreLink in mind, so this
503 * is a no-op if the service is BaltimoreLink.
504 */
505 function resize_ticket() {
506 /* Get the "servicename" from the querystring if it's there */
507 const params = new URLSearchParams(document.location.search);
508 const tbg = document.getElementById("ticketbg");
509 const t = document.getElementById("ticket");
510 const sn = document.getElementById("servicename");
511
512 if (params.get("servicename") === "Commuter Bus") {
513 /* The top of the background is initially at y=246.859, and
514 * we scale it by a factor of 1.12 to y=276.482 for a change
515 * of 29.623. So after we scale it, we translate it upwards
516 * by that amount to put it back where it started. */
517 tbg.setAttribute("transform", "translate(0 -29.623) scale(1 1.12)");
518
519 /* Now translate the entire ticket up by the magic amount, 1/5
520 * of the size change we made to the background. This ratio
521 * was found by measuring pixels in side-by-side screenshots
522 * of BaltimoreLink and Commuter Bus tickets. */
523 t.setAttribute("transform", "translate(0 -9.33)");
524
525 /* More magic numbers discovered by comparing the two
526 * tickets overlayed in inkscape */
527 sn.setAttribute("transform", "translate(0 64.28)");
528 }
529 else if (params.get("servicename") === "MARC Train") {
530 /* insane tricks are explained above */
531 tbg.setAttribute("transform",
532 "translate(0 -72.378) scale(1 1.2932)");
533 t.setAttribute("transform", "translate(0 -67.17)");
534 sn.setAttribute("transform", "translate(0 131.0)");
535 }
536 }
537
538
539 /**
540 * Set the security code from the querystring if it was given;
541 * otherwise generate a random code.
542 */
543 function set_code() {
544 const ct = document.getElementById("codetext");
545
546 /* Get the "code" from the querystring if it's there */
547 const params = new URLSearchParams(document.location.search);
548 if (params.get("code")) {
549 ct.textContent = params.get("code").toUpperCase();
550 }
551 else {
552 /* Otherwise, use a random code */
553 const bucket = ["0","1","2","3","4","5","6","7","8","9",
554 "A","B","C","D","E","F","G","H","I","J",
555 "K","L","M","N","O","P","Q","R","S","T",
556 "U","V","W","X","Y","Z"];
557
558 /* Two random ints between 0 and 35 */
559 const i1 = Math.floor(Math.random() * 36);
560 const i2 = Math.floor(Math.random() * 36);
561 const d1 = bucket[i1];
562 const d2 = bucket[i2];
563 ct.textContent = d1 + d2;
564 }
565 }
566
567
568 /**
569 * Center the security code within its container.
570 *
571 * Some codes like "II" and "WW" can take up wildly different
572 * amounts of horizonetal space, but they should always be
573 * centered inside their little red box. This turns out to be
574 * harder than it sounds because we can only find the width of
575 * the code in browser coordinates, whereas its "x" coordinate
576 * is in SVG coordinates. Anyway, we do it.
577 */
578 function center_code() {
579 /* Center the security code inside its red box */
580 const ct = document.getElementById("codetext");
581 const bg = document.getElementById("codebg");
582
583 /* First, find the center of the red box */
584 const r1 = bg.getBoundingClientRect();
585 const c1 = r1.left + (r1.width / 2);
586
587 /* Now the center of the code text */
588 const r2 = ct.getBoundingClientRect();
589 const c2 = r2.left + (r2.width / 2);
590
591 /* What do we add to c2 to make it equal to c1? */
592 const hdelta = c1 - c2;
593
594 /* We've measured everything so far in "client rect"
595 * coordinates, because that's the only available measurement
596 * we have for the width of the <text> element. But when we
597 * reposition that <text> element, it will be by adjusting its
598 * "x" attribute, and that attribute uses a different coordinate
599 * system than the client rect does. Specifically, "x" refers to
600 * an offset within the SVG's coordinate system, and the client
601 * rect coordinates are pixels on-screen. To convert between the
602 * two, we can take the "width" attribute of the background
603 * element and compare it to the width of the background
604 * element's client rect. Since the size of the background is
605 * fixed, this should give us a multiplier that turns client rect
606 * distances (what we have) into SVG distances (what we want) */
607 const client_to_svg = parseFloat(bg.getAttribute("width"))/r1.width;
608
609 /* Convert hdelta from client rect to SVG coordinates */
610 const svg_hdelta = hdelta * client_to_svg;
611
612 /* Since this <text> element has an "x" attribute it's easier for
613 * us to shift that than it is to mess with the "left" style. */
614 ct.setAttribute("x", parseFloat(ct.getAttribute("x")) + svg_hdelta);
615 }
616
617 /**
618 * Set the ticket's expiration date and time.
619 *
620 * BaltimoreLink and MARC Train tickets expire after 90 minutes;
621 * while Commuter Bus tickets expire after 10 minutes.
622 */
623 function set_ticket_expiry() {
624 /* There are two parameters, time and date, that we store in one
625 * underlying "date" variable. */
626 const date = new Date();
627
628 /* BaltimoreLink and MARC Train */
629 let minutes = 90;
630 const params = new URLSearchParams(document.location.search);
631 if (params.get("servicename") === "Commuter Bus") {
632 /* Commuter bus tickets are only valid for ten minutes */
633 minutes = 10;
634 }
635
636 /* We use the low-level get/setTime to change the number of
637 * milliseconds since the epoch that this date represents
638 * Obviously correct, and avoids all suspicious corner cases
639 * for a few more decades. */
640 date.setTime(date.getTime() + (minutes*60*1000));
641
642 tt = document.getElementById("tickettime");
643 tt.textContent = date.toLocaleTimeString();
644
645 const td = document.getElementById("ticketdate");
646 const dateopts = {
647 day: "2-digit",
648 month: "2-digit",
649 year: "2-digit"
650 };
651 td.textContent = date.toLocaleDateString("en-US", dateopts);
652 }
653
654
655 /**
656 * Swap the day/night sky colors.
657 *
658 * We use CSS classes to keep track of the current state because
659 * it's a tiny bit cleaner than a global variable, but for some
660 * reason we can't use those same classes to actually change the
661 * color. (The classes, change, but the color doesn't.) Rather
662 * than waste time trying to explain this, we just set the "fill"
663 * attribute ourselves whenever we swap classes.
664 */
665 function swap_day_night() {
666 const sky = document.getElementById("sky");
667
668 if (sky.getAttribute("class") === "night") {
669 sky.setAttribute("fill", "#efb02f");
670 sky.setAttribute("class", "day");
671 }
672 else {
673 /* Put this case second so that the first time the
674 * screen is tapped (when there are no classes on
675 * the sky element) the color still changes. */
676 sky.setAttribute("fill", "#143b66");
677 sky.setAttribute("class", "night");
678 }
679 }
680
681
682 /**
683 * Compute the zone (string) for the given origin/destination pair.
684 *
685 * If we don't know it or if you chose in invalid pair (destination
686 * not on the same line as your origin?) then null is returned.
687 */
688 function compute_marc_zone(src, dest) {
689
690 /* Sorted on the first component, then the second */
691 const zone_map = {
692 BAL_BWE: 2,
693 BAL_BWI: 1,
694 BAL_SEB: 3,
695 BAL_WAS: 4,
696 BAL_WBL: 1,
697 BCA_CPK: 3,
698 BCA_WAS: 4,
699 BWE_BWI: 1,
700 BWE_SEB: 1,
701 BWE_WAS: 2,
702 BWE_WBL: 2,
703 BWI_WAS: 3,
704 BWI_WBL: 1
705 };
706
707 /* Forward direction key for zone_map */
708 const fwd = src + "_" + dest;
709
710 /* Reverse direction key for zone_map. The zone_map only
711 * has them listed in one direction, so we check both
712 * directions here. */
713 const rev = dest + "_" + src;
714
715 /* The default. Obviously wrong for when we don't
716 * have the necessary data. */
717 let zone = -1;
718
719 if (zone_map[fwd]) {
720 zone = zone_map[fwd];
721 }
722 else if (zone_map[rev]) {
723 zone = zone_map[rev];
724 }
725
726 /* Convert the number to a string */
727 switch (zone) {
728 case 1:
729 return "One Zone";
730 case 2:
731 return "Two Zone";
732 case 3:
733 return "Three Zone";
734 case 4:
735 return "Four Zone";
736 default:
737 return null;
738 }
739 }
740
741
742 /**
743 * Compute and set the zone.
744 *
745 * We can be given a zone in two ways. First, on Commuter Bus
746 * tickets, it is given explicitly via the querystring. But
747 * It can also be specified implicitly via the origin and
748 * destination on a MARC Train ticket. Here we try both and
749 * then call set_zone() with the result if something worked.
750 */
751 function compute_and_set_zone() {
752 const params = new URLSearchParams(document.location.search);
753 const src = params.get("origin");
754 const dest = params.get("destination");
755
756 if (src && dest) {
757 /* MARC Train. We can assume that compute_marc_zone() doesn't
758 * return null because that's part of our form validation. */
759 const zone = compute_marc_zone(src, dest);
760 set_zone(zone);
761 }
762 else if (params.get("zone")) {
763 /* Commuter Bus */
764 set_zone(params.get("zone"));
765 }
766 }
767
768
769 /**
770 * Set the origin and destination for the MARC Train if they
771 * were provided, and unhide them if so.
772 */
773 function set_marc_origin_destination() {
774 const params = new URLSearchParams(document.location.search);
775 if (!params.get("origin") || !params.get("destination")) {
776 return;
777 }
778
779 const src = params.get("origin");
780 const dest = params.get("destination");
781
782 /* origindest contains both the origin and destination */
783 const origindest = document.getElementById("origindest");
784
785 const origin = document.getElementById("origin");
786 const destination = document.getElementById("destination");
787
788 origin.textContent = params.get("origin");
789 destination.textContent = params.get("destination");
790
791 origindest.style.display = "block"; /* hidden by default */
792 }
793
794
795 /**
796 * Hide the menu and display the ticket. This is what happens
797 * when you submit the form.
798 */
799 function go() {
800 /* To create our "window" onto the scene, we're going to slide the
801 * SVG off the left-hand side of the screen, and we don't want
802 * scroll bars to appear. */
803 document.body.style.overflow = "hidden";
804 document.body.style.margin = "0";
805 document.body.style.padding = "0";
806
807 const svg = document.querySelector("svg");
808 const menu = document.getElementById("menu");
809 svg.style.display = "initial";
810 menu.style.display = "none";
811 }
812
813 /**
814 * Validate the MARC form's origin/destination.
815 *
816 * We don't want the user to be able to choose a pair of stops that
817 * aren't actually connected by the same MARC line. If we don't have
818 * zone information for the (origin,destination) pair, that indicates
819 * that it's probably not a valid choice; otherwise I would have
820 * filled in the information from the CharmPass app already.
821 */
822 function validate_origin_destination(event) {
823 const origins = document.getElementsByName("origin");
824 const destinations = document.getElementsByName("destination");
825
826 let src = null;
827 let dest = null;
828 origins.forEach((x) => { if (x.checked) src = x; })
829 destinations.forEach((x) => {
830 if (x.checked) dest = x;
831
832 /* clear all errors before possibly setting one */
833 x.setCustomValidity('');
834 })
835
836 if (src.value === dest.value) {
837 let err = "Origin and destination are the same!";
838 dest.setCustomValidity(err);
839 }
840 else if (compute_marc_zone(src.value, dest.value) === null) {
841 let err = "Origin and destination are on different lines!";
842 dest.setCustomValidity(err);
843 }
844 }
845
846 /*****************************************************/
847 /* Add event handlers for all of the functions above */
848 /*****************************************************/
849
850 const params = new URLSearchParams(document.location.search);
851 if (params.get("go")) {
852 /* First unhide the SVG (swap it with the form) */
853 window.addEventListener("load", go);
854
855 /* Center the ticket once when the page has loaded */
856 window.addEventListener("load", center_ticket);
857
858 /* Re-center the ticket when the window is resized */
859 window.addEventListener("resize", center_ticket);
860
861 /* Set the service identifier when the page has loaded */
862 window.addEventListener("load", set_service_id);
863
864 /* Set the service name when the page has loaded */
865 window.addEventListener("load", set_service_name);
866
867 /* Resize the ticket background if necessary */
868 window.addEventListener("load", resize_ticket);
869
870 /* Set the security code text when the page has loaded */
871 window.addEventListener("load", set_code);
872
873 /* Center the security code text when the page has loaded; in
874 * particular, after we set the code. */
875 window.addEventListener("load", center_code);
876
877 /* Set the ticket expiration date/time upon page load */
878 window.addEventListener("load", set_ticket_expiry);
879
880 /* Set the MARC Train origin and destination, if applicable */
881 window.addEventListener("load", set_marc_origin_destination);
882
883 /* Compute and set the zone, if applicable */
884 window.addEventListener("load", compute_and_set_zone);
885
886 /* Swap colors when the screen is tapped */
887 document.body.addEventListener("click", swap_day_night);
888 }
889 else {
890 /* If we haven't submitted the form yet, set up change handlers
891 * for the origin/destination radio buttons that validate that
892 * the origin and destination are on the same line. */
893 document.getElementsByName("origin").forEach(
894 (x) => x.addEventListener("change", validate_origin_destination)
895 );
896 document.getElementsByName("destination").forEach(
897 (x) => x.addEventListener("change", validate_origin_destination)
898 );
899
900 /* Also do it when the page loads, because firefox likes to
901 * remember your selection even after the page reloads. */
902 window.addEventListener("load", validate_origin_destination);
903 }
904
905 </script>
906 </body>
907 </html>