5 <meta name=
"viewport" content=
"width=device-width, initial-scale=1" />
8 href=
"data:image/svg+xml;base64,@FAVICON@" />
11 CharmBypass: that transit equity y'all
16 /* For consistency with the SVG */
17 font-family: sans-serif;
34 /* Display form errors for the one browser that doesn't support
35 * them natively, mobile Firefox. We use "visibility" to toggle
36 * it on and off, but "display" to hide it completely in non-
37 * stupid web browsers. */
45 /* Set the height to
100% of the screen, which we'll keep; and the
46 * initial position to (
0,
0), which we're going to change
47 * every time the window is resized, because the exact amount
48 * that we have to slide the SVG to the left to get the ticket
49 * into the center will change. */
55 /* Hide everything by default. We only show it once the user has
56 * submitted the menu form */
60 /* The blinking fade in/out animation for the ticket date and time */
67 #tickettime, #ticketdate {
68 /*
300 two-second blinks is ten minutes */
69 animation: blink
2s linear
300;
72 /* Define, load, and specify the custom font we use for the ticket
73 * date, time, and service name. */
75 font-family: "CharmBypass Regular";
77 url("data:font/woff2;base64,@CBPREGULAR@") format("woff2")
80 #origindest, #servicename, #tickettime, #ticketdate, #codetext, #zone {
81 font-family: "CharmBypass Regular", sans-serif;
85 font-family: "CharmBypass Bold";
87 url("data:font/woff2;base64,@CBPBOLD@") format("woff2")
91 font-family: "CharmBypass Bold", sans-serif;
94 /************************/
95 /* Scrolling animations */
96 /************************/
100 from { transform: translateX(
0%); }
101 to { transform: translateX(-
100%); }
105 animation: busroll
23s linear infinite;
110 @keyframes tramroll {
111 from { transform: translateX(
0%); }
112 to { transform: translateX(
100%); }
116 animation: tramroll
17s linear infinite;
121 @keyframes trainroll {
122 from { transform: translateX(
0%); }
123 to { transform: translateX(
100%); }
127 animation: trainroll
11s linear infinite;
132 @keyframes cloudsfloat {
133 from { transform: translateX(
0%); }
134 to { transform: translateX(-
50%); }
138 animation: cloudsfloat
40s linear infinite;
141 @keyframes cloudscopyfloat {
142 from { transform: translateX(
0%); }
143 to { transform: translateX(-
50%); }
147 animation: cloudscopyfloat
40s linear infinite;
152 @keyframes treespass {
153 from { transform: translateX(
0%); }
154 to { transform: translateX(-
50%); }
158 /* The trees move a little faster than the clouds */
159 animation: treespass
30s linear infinite;
162 @keyframes treescopypass {
163 from { transform: translateX(
0%); }
164 to { transform: translateX(-
50%); }
168 /* The trees move a little faster than the clouds */
169 animation: treescopypass
30s linear infinite;
174 @keyframes cityscroll {
175 from { transform: translateX(
0%); }
176 to { transform: translateX(-
50%); }
180 /* The city moves faster than the clouds but slower
182 animation: cityscroll
35s linear infinite;
185 @keyframes citycopyscroll {
186 from { transform: translateX(
0%); }
187 to { transform: translateX(-
50%); }
191 /* The city moves faster than the clouds but slower
193 animation: citycopyscroll
35s linear infinite;
201 <h2>that transit equity y'all
</h2>
204 <em>Hint:
</em> If they start checking it, the daily security
205 code stays the same all day and is the same on a $
2 bus ticket
206 as it is on a $
9 MARC ticket. It's also the same on every phone.
211 <legend>Local Bus, Light Rail, or Metro
</legend>
214 Daily security code (optional):
222 pattern=
"[a-zA-Z0-9]*" />
224 <input type=
"hidden" name=
"servicename" value=
"BaltimoreLink" />
225 <input type=
"submit" name=
"go" value=
"Generate Ticket" />
230 <legend>Commuter Bus
</legend>
231 <input type=
"hidden" name=
"serviceid" value=
"R" />
232 <input type=
"hidden" name=
"servicename" value=
"Commuter Bus" />
236 Daily security code (optional):
244 pattern=
"[a-zA-Z0-9]*" />
249 <input type=
"radio" required
253 <label for=
"zone1">Zone
1</label>
256 <input type=
"radio" required
260 <label for=
"zone2">Zone
2</label>
263 <input type=
"radio" required checked
267 <label for=
"zone3">Zone
3</label>
270 <input type=
"radio" required
274 <label for=
"zone4">Zone
4</label>
277 <input type=
"radio" required
281 <label for=
"zone5">Zone
5</label>
284 <input type=
"submit" name=
"go" value=
"Generate Ticket" />
289 <legend>MARC Train
</legend>
293 Daily security code (optional):
301 pattern=
"[a-zA-Z0-9]*" />
306 <input type=
"radio" required checked
310 <label for=
"origin1">Baltimore/Penn (Penn Line)
</label>
313 <input type=
"radio" required
317 <label for=
"origin2">Baltimore/Camden (Camden Line)
</label>
320 <input type=
"radio" required
324 <label for=
"origin3">Bowie State (Penn Line)
</label>
327 <input type=
"radio" required
331 <label for=
"origin4">BWI Airport (Penn Line)
</label>
334 <input type=
"radio" required
338 <label for=
"origin5">College Park (Camden Line)
</label>
341 <input type=
"radio" required
345 <label for=
"origin6">Seabrook (Penn Line)
</label>
348 <input type=
"radio" required
352 <label for=
"origin7">Washington D.C.
</label>
355 <input type=
"radio" required
359 <label for=
"origin8">West Baltimore (Penn Line)
</label>
364 <input type=
"radio" required
368 <label for=
"destination1">Baltimore/Penn (Penn Line)
</label>
371 <input type=
"radio" required
375 <label for=
"destination2">Baltimore/Camden (Camden Line)
</label>
378 <input type=
"radio" required
382 <label for=
"destination3">Bowie State (Penn Line)
</label>
385 <input type=
"radio" required
389 <label for=
"destination4">BWI Airport (Penn Line)
</label>
392 <input type=
"radio" required
396 <label for=
"destination5">College Park (Camden Line)
</label>
399 <input type=
"radio" required
403 <label for=
"destination6">Seabrook (Penn Line)
</label>
406 <input type=
"radio" required checked
410 <label for=
"destination7">Washington D.C.
</label>
413 <input type=
"radio" required
417 <label for=
"destination8">West Baltimore (Penn Line)
</label>
420 <p id=
"marc-form-errors">OK
</p>
422 <input type=
"hidden" name=
"serviceid" value=
"R" />
423 <input type=
"hidden" name=
"servicename" value=
"MARC Train" />
427 value=
"Generate Ticket" />
437 * Center the ticket within the browser by translating the SVG
438 * until the ticket and the viewport centerlines coincide.
440 function center_ticket() {
441 /* We're relying on the SVG being the full height of the
442 * viewport already, and on the aspect ratio being
443 * preserved. First, find the center of the ticket. */
444 const r = document.getElementById("ticket").getBoundingClientRect();
445 const c = r.left + (r.width /
2);
447 /* That's the center-line of the ticket. We want to move it to
448 * the center-line of the viewport. */
449 const vc = document.documentElement.clientWidth /
2;
451 /* This is how much we need to translate the SVG */
452 const hdelta = vc - c;
454 /* But before we can set the absolute left-coordinate of the
455 * SVG, we need to know where it is now. Note: without the
456 * "px" this doesn't default to pixels like CSS does. */
457 const svg = document.querySelector("svg");
458 svg.style.left = (svg.getBoundingClientRect().left + hdelta) + "px";
463 * Set the service identifier from the querystring if it's there.
464 * Otherwise, leave it at the default of "F".
466 function set_service_id() {
467 const sid = document.getElementById("serviceid");
469 /* Get the "serviceid" from the querystring if it's there */
470 const params = new URLSearchParams(document.location.search);
471 if (params.get("serviceid")) {
472 sid.textContent = params.get("serviceid");
478 * Set the service name from the querystring if it's there.
479 * Otherwise, leave it at the default of "BaltimoreLink".
481 function set_service_name() {
482 const sid = document.getElementById("servicename");
484 /* Get the "servicename" from the querystring if it's there */
485 const params = new URLSearchParams(document.location.search);
486 if (params.get("servicename")) {
487 sid.textContent = params.get("servicename");
493 * Set the zone from the given "zone" parameter and then unhide it.
495 function set_zone(zone) {
496 const z = document.getElementById("zone");
498 z.textContent = zone;
499 z.style.display = "block"; /* hidden by default */
504 * Resize the ticket background based on the service name.
505 * The BaltimoreLink, Commuter Bus, and MARC Train tickets
506 * are all different heights and are arranged vertically a
509 * Rather than design three completelty separate tickets and
510 * then have to keep track of which one we're using, I have
511 * instead decided to use one ticket and to reposition it
512 * on-the-fly based on the service name. This is necessarily
513 * a bit ugly because it involves a lot of magic numbers that
514 * can only be explained if you open up inkscape with a CharmPass
515 * screenshot to see where things belong and how to get them there.
517 * The SVG was designed with BaltimoreLink in mind, so this
518 * is a no-op if the service is BaltimoreLink.
520 function resize_ticket() {
521 /* Get the "servicename" from the querystring if it's there */
522 const params = new URLSearchParams(document.location.search);
523 const tbg = document.getElementById("ticketbg");
524 const t = document.getElementById("ticket");
525 const sn = document.getElementById("servicename");
527 if (params.get("servicename") === "Commuter Bus") {
528 /* The top of the background is initially at y=
246.859, and
529 * we scale it by a factor of
1.12 to y=
276.482 for a change
530 * of
29.623. So after we scale it, we translate it upwards
531 * by that amount to put it back where it started. */
532 tbg.setAttribute("transform", "translate(
0 -
29.623) scale(
1 1.12)");
534 /* Now translate the entire ticket up by the magic amount,
1/
5
535 * of the size change we made to the background. This ratio
536 * was found by measuring pixels in side-by-side screenshots
537 * of BaltimoreLink and Commuter Bus tickets. */
538 t.setAttribute("transform", "translate(
0 -
9.33)");
540 /* More magic numbers discovered by comparing the two
541 * tickets overlayed in inkscape */
542 sn.setAttribute("transform", "translate(
0 64.28)");
544 else if (params.get("servicename") === "MARC Train") {
545 /* insane tricks are explained above */
546 tbg.setAttribute("transform",
547 "translate(
0 -
72.378) scale(
1 1.2932)");
548 t.setAttribute("transform", "translate(
0 -
67.17)");
549 sn.setAttribute("transform", "translate(
0 131.0)");
555 * Set the security code from the querystring if it was given;
556 * otherwise generate a random code.
558 function set_code() {
559 const ct = document.getElementById("codetext");
561 /* Get the "code" from the querystring if it's there */
562 const params = new URLSearchParams(document.location.search);
563 if (params.get("code")) {
564 ct.textContent = params.get("code").toUpperCase();
567 /* Otherwise, use a random code */
568 const bucket = ["
0","
1","
2","
3","
4","
5","
6","
7","
8","
9",
569 "A","B","C","D","E","F","G","H","I","J",
570 "K","L","M","N","O","P","Q","R","S","T",
571 "U","V","W","X","Y","Z"];
573 /* Two random ints between
0 and
35 */
574 const i1 = Math.floor(Math.random() *
36);
575 const i2 = Math.floor(Math.random() *
36);
576 const d1 = bucket[i1];
577 const d2 = bucket[i2];
578 ct.textContent = d1 + d2;
584 * Center the security code within its container.
586 * Some codes like "II" and "WW" can take up wildly different
587 * amounts of horizonetal space, but they should always be
588 * centered inside their little red box. This turns out to be
589 * harder than it sounds because we can only find the width of
590 * the code in browser coordinates, whereas its "x" coordinate
591 * is in SVG coordinates. Anyway, we do it.
593 function center_code() {
594 /* Center the security code inside its red box */
595 const ct = document.getElementById("codetext");
596 const bg = document.getElementById("codebg");
598 /* First, find the center of the red box */
599 const r1 = bg.getBoundingClientRect();
600 const c1 = r1.left + (r1.width /
2);
602 /* Now the center of the code text */
603 const r2 = ct.getBoundingClientRect();
604 const c2 = r2.left + (r2.width /
2);
606 /* What do we add to c2 to make it equal to c1? */
607 const hdelta = c1 - c2;
609 /* We've measured everything so far in "client rect"
610 * coordinates, because that's the only available measurement
611 * we have for the width of the
<text> element. But when we
612 * reposition that
<text> element, it will be by adjusting its
613 * "x" attribute, and that attribute uses a different coordinate
614 * system than the client rect does. Specifically, "x" refers to
615 * an offset within the SVG's coordinate system, and the client
616 * rect coordinates are pixels on-screen. To convert between the
617 * two, we can take the "width" attribute of the background
618 * element and compare it to the width of the background
619 * element's client rect. Since the size of the background is
620 * fixed, this should give us a multiplier that turns client rect
621 * distances (what we have) into SVG distances (what we want) */
622 const client_to_svg = parseFloat(bg.getAttribute("width"))/r1.width;
624 /* Convert hdelta from client rect to SVG coordinates */
625 const svg_hdelta = hdelta * client_to_svg;
627 /* Since this
<text> element has an "x" attribute it's easier for
628 * us to shift that than it is to mess with the "left" style. */
629 ct.setAttribute("x", parseFloat(ct.getAttribute("x")) + svg_hdelta);
633 * Set the ticket's expiration date and time.
635 * BaltimoreLink and MARC Train tickets expire after
90 minutes;
636 * while Commuter Bus tickets expire after
10 minutes.
638 function set_ticket_expiry() {
639 /* There are two parameters, time and date, that we store in one
640 * underlying "date" variable. */
641 const date = new Date();
643 /* BaltimoreLink and MARC Train */
645 const params = new URLSearchParams(document.location.search);
646 if (params.get("servicename") === "Commuter Bus") {
647 /* Commuter bus tickets are only valid for ten minutes */
651 /* We use the low-level get/setTime to change the number of
652 * milliseconds since the epoch that this date represents
653 * Obviously correct, and avoids all suspicious corner cases
654 * for a few more decades. */
655 date.setTime(date.getTime() + (minutes*
60*
1000));
657 tt = document.getElementById("tickettime");
658 tt.textContent = date.toLocaleTimeString();
660 const td = document.getElementById("ticketdate");
666 td.textContent = date.toLocaleDateString("en-US", dateopts);
671 * Swap the day/night sky colors.
673 * We use CSS classes to keep track of the current state because
674 * it's a tiny bit cleaner than a global variable, but for some
675 * reason we can't use those same classes to actually change the
676 * color. (The classes, change, but the color doesn't.) Rather
677 * than waste time trying to explain this, we just set the "fill"
678 * attribute ourselves whenever we swap classes.
680 function swap_day_night() {
681 const sky = document.getElementById("sky");
683 if (sky.getAttribute("class") === "night") {
684 sky.setAttribute("fill", "#efb02f");
685 sky.setAttribute("class", "day");
688 /* Put this case second so that the first time the
689 * screen is tapped (when there are no classes on
690 * the sky element) the color still changes. */
691 sky.setAttribute("fill", "#
143b66");
692 sky.setAttribute("class", "night");
698 * Compute the zone (string) for the given origin/destination pair.
700 * If we don't know it or if you chose in invalid pair (destination
701 * not on the same line as your origin?) then null is returned.
703 function compute_marc_zone(src, dest) {
705 /* Sorted on the first component, then the second */
722 /* Forward direction key for zone_map */
723 const fwd = src + "_" + dest;
725 /* Reverse direction key for zone_map. The zone_map only
726 * has them listed in one direction, so we check both
727 * directions here. */
728 const rev = dest + "_" + src;
730 /* The default. Obviously wrong for when we don't
731 * have the necessary data. */
735 zone = zone_map[fwd];
737 else if (zone_map[rev]) {
738 zone = zone_map[rev];
741 /* Convert the number to a string */
758 * Compute and set the zone.
760 * We can be given a zone in two ways. First, on Commuter Bus
761 * tickets, it is given explicitly via the querystring. But
762 * It can also be specified implicitly via the origin and
763 * destination on a MARC Train ticket. Here we try both and
764 * then call set_zone() with the result if something worked.
766 function compute_and_set_zone() {
767 const params = new URLSearchParams(document.location.search);
768 const src = params.get("origin");
769 const dest = params.get("destination");
772 /* MARC Train. We can assume that compute_marc_zone() doesn't
773 * return null because that's part of our form validation. */
774 const zone = compute_marc_zone(src, dest);
777 else if (params.get("zone")) {
779 set_zone(params.get("zone"));
785 * Set the origin and destination for the MARC Train if they
786 * were provided, and unhide them if so.
788 function set_marc_origin_destination() {
789 const params = new URLSearchParams(document.location.search);
790 if (!params.get("origin") || !params.get("destination")) {
794 const src = params.get("origin");
795 const dest = params.get("destination");
797 /* origindest contains both the origin and destination */
798 const origindest = document.getElementById("origindest");
800 const origin = document.getElementById("origin");
801 const destination = document.getElementById("destination");
803 origin.textContent = params.get("origin");
804 destination.textContent = params.get("destination");
806 origindest.style.display = "block"; /* hidden by default */
811 * Hide the menu and display the ticket. This is what happens
812 * when you submit the form.
815 /* To create our "window" onto the scene, we're going to slide the
816 * SVG off the left-hand side of the screen, and we don't want
817 * scroll bars to appear. */
818 document.body.style.overflow = "hidden";
819 document.body.style.margin = "
0";
820 document.body.style.padding = "
0";
822 const svg = document.querySelector("svg");
823 const menu = document.getElementById("menu");
824 svg.style.display = "initial";
825 menu.style.display = "none";
829 * Determine if the user agent is mobile Firefox.
831 function ua_is_mobile_ff() {
832 const ua = navigator.userAgent.toLowerCase();
833 return (ua.includes("firefox") && ua.includes("mobile"));
837 * Validate the MARC form's origin/destination.
839 * We don't want the user to be able to choose a pair of stops that
840 * aren't actually connected by the same MARC line. If we don't have
841 * zone information for the (origin,destination) pair, that indicates
842 * that it's probably not a valid choice; otherwise I would have
843 * filled in the information from the CharmPass app already.
845 * All browsers except mobile Firefox let us call setCustomValidity()
846 * to provide an error message that is displayed if the user tries
847 * to submit invalid choices. But amazingly, mobile Firefox does not:
849 * https://bugzilla.mozilla.org/show_bug.cgi?id=
1510450
851 * Instead we have to work around it (in that one browser) by
852 * showing/hiding a paragraph that we fill with the errors.
854 function validate_origin_destination(event) {
855 const origins = document.getElementsByName("origin");
856 const destinations = document.getElementsByName("destination");
857 const mfe = document.getElementById("marc-form-errors");
858 const marcsubmit = document.getElementById("marc-submit");
860 if (ua_is_mobile_ff()) {
861 /* Even though this is only for one browser, empty paragraphs
862 * are handled inconsistently and should be avoided as a rule.
863 * So, we make it say "OK" before we hide it. */
864 mfe.textContent = "OK";
865 mfe.style.visibility = "hidden";
866 marcsubmit.disabled = false;
871 origins.forEach((x) =
> { if (x.checked) src = x; })
872 destinations.forEach((x) =
> {
873 if (x.checked) dest = x;
875 /* clear all errors before possibly setting one */
876 x.setCustomValidity('');
879 if (src.value === dest.value) {
880 let err = "Origin and destination are the same";
881 dest.setCustomValidity(err);
883 if (ua_is_mobile_ff()) {
884 mfe.textContent = err;
885 mfe.style.visibility = "visible";
886 marcsubmit.disabled = true;
889 else if (compute_marc_zone(src.value, dest.value) === null) {
890 let err = "Origin and destination are on different lines";
891 dest.setCustomValidity(err);
893 if (ua_is_mobile_ff()) {
894 mfe.textContent = err;
895 mfe.style.visibility = "visible";
896 marcsubmit.disabled = true;
901 /*****************************************************/
902 /* Add event handlers for all of the functions above */
903 /*****************************************************/
905 const params = new URLSearchParams(document.location.search);
906 if (params.get("go")) {
907 /* First unhide the SVG (swap it with the form) */
908 window.addEventListener("load", go);
910 /* Center the ticket once when the page has loaded */
911 window.addEventListener("load", center_ticket);
913 /* Re-center the ticket when the window is resized */
914 window.addEventListener("resize", center_ticket);
916 /* Set the service identifier when the page has loaded */
917 window.addEventListener("load", set_service_id);
919 /* Set the service name when the page has loaded */
920 window.addEventListener("load", set_service_name);
922 /* Resize the ticket background if necessary */
923 window.addEventListener("load", resize_ticket);
925 /* Set the security code text when the page has loaded */
926 window.addEventListener("load", set_code);
928 /* Center the security code text when the page has loaded; in
929 * particular, after we set the code. */
930 window.addEventListener("load", center_code);
932 /* Set the ticket expiration date/time upon page load */
933 window.addEventListener("load", set_ticket_expiry);
935 /* Set the MARC Train origin and destination, if applicable */
936 window.addEventListener("load", set_marc_origin_destination);
938 /* Compute and set the zone, if applicable */
939 window.addEventListener("load", compute_and_set_zone);
941 /* Swap colors when the screen is tapped */
942 document.body.addEventListener("click", swap_day_night);
945 /* If we haven't submitted the form yet, set up change handlers
946 * for the origin/destination radio buttons that validate that
947 * the origin and destination are on the same line. */
948 document.getElementsByName("origin").forEach(
949 (x) =
> x.addEventListener("change", validate_origin_destination)
951 document.getElementsByName("destination").forEach(
952 (x) =
> x.addEventListener("change", validate_origin_destination)
955 /* Also do it when the page loads, because firefox likes to
956 * remember your selection even after the page reloads. */
957 window.addEventListener("load", validate_origin_destination);
959 /* Finally, we have to babysit mobile Firefox, who doesn't
960 * support HTML5 form validation going into
2024. Turn on
961 * the little form errors paragraph so we can toggle its
962 * visibility (and make it display the error) when the user
963 * makes an invalid selection. */
964 window.addEventListener("load", () =
> {
965 if (ua_is_mobile_ff()) {
966 const mfe = document.getElementById("marc-form-errors");
967 mfe.style.display = "block";