5 <meta name=
"viewport" content=
"width=device-width, initial-scale=1" />
8 href=
"data:image/svg+xml;base64,@FAVICON@" />
11 CharmBypass: got that transit equity
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
15s linear infinite;
110 @keyframes tramroll {
111 from { transform: translateX(
0%); }
112 to { transform: translateX(
100%); }
116 animation: tramroll
15s linear infinite;
121 @keyframes trainroll {
122 from { transform: translateX(
0%); }
123 to { transform: translateX(
100%); }
127 animation: trainroll
10s linear infinite;
132 @keyframes cloudsfloat {
133 from { transform: translateX(
0%); }
134 to { transform: translateX(-
50%); }
138 animation: cloudsfloat
25s linear infinite;
141 @keyframes cloudscopyfloat {
142 from { transform: translateX(
0%); }
143 to { transform: translateX(-
50%); }
147 animation: cloudscopyfloat
25s 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
16s 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
16s 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
20s 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
20s linear infinite;
201 <p><strong>got that
<em>transit equity
</em></strong></p>
205 <legend>Local Bus, Light Rail, or Metro
</legend>
208 Daily security code (optional):
216 pattern=
"[a-zA-Z0-9]*" />
218 <input type=
"hidden" name=
"servicename" value=
"BaltimoreLink" />
219 <input type=
"submit" name=
"go" value=
"Generate Ticket" />
224 <legend>Commuter Bus
</legend>
225 <input type=
"hidden" name=
"serviceid" value=
"R" />
226 <input type=
"hidden" name=
"servicename" value=
"Commuter Bus" />
230 Daily security code (optional):
238 pattern=
"[a-zA-Z0-9]*" />
242 Zone
<sup>†</sup>:
245 <input type=
"radio" required
249 <label for=
"zone1">Zone
1</label>
252 <input type=
"radio" required
256 <label for=
"zone2">Zone
2</label>
259 <input type=
"radio" required checked
263 <label for=
"zone3">Zone
3</label>
266 <input type=
"radio" required
270 <label for=
"zone4">Zone
4</label>
273 <input type=
"radio" required
277 <label for=
"zone5">Zone
5</label>
280 <input type=
"submit" name=
"go" value=
"Generate Ticket" />
284 On the MTA's PDF schedule for your route
290 <legend>MARC Train
</legend>
294 Daily security code (optional):
302 pattern=
"[a-zA-Z0-9]*" />
307 <input type=
"radio" required checked
311 <label for=
"origin_BAL">Baltimore/Penn (Penn Line)
</label>
314 <input type=
"radio" required
318 <label for=
"origin_BCA">Baltimore/Camden (Camden Line)
</label>
321 <input type=
"radio" required
325 <label for=
"origin_BWE">Bowie State (Penn Line)
</label>
328 <input type=
"radio" required
332 <label for=
"origin_BWI">BWI Airport (Penn Line)
</label>
335 <input type=
"radio" required
339 <label for=
"origin_CPK">College Park (Camden Line)
</label>
342 <input type=
"radio" required
346 <label for=
"origin_FRC">Frederick (Brunswick Line)
</label>
349 <input type=
"radio" required
353 <label for=
"origin_HAE">Halethorpe (Penn Line)
</label>
356 <input type=
"radio" required
360 <label for=
"origin_NCR">New Carrollton (Penn Line)
</label>
363 <input type=
"radio" required
367 <label for=
"origin_SEB">Seabrook (Penn Line)
</label>
370 <input type=
"radio" required
374 <label for=
"origin_WAS">Washington D.C.
</label>
377 <input type=
"radio" required
381 <label for=
"origin_WBL">West Baltimore (Penn Line)
</label>
386 <input type=
"radio" required
390 <label for=
"destination_BAL">Baltimore/Penn (Penn Line)
</label>
393 <input type=
"radio" required
397 <label for=
"destination_BCA">Baltimore/Camden (Camden Line)
</label>
400 <input type=
"radio" required
404 <label for=
"destination_BWE">Bowie State (Penn Line)
</label>
407 <input type=
"radio" required
411 <label for=
"destination_BWI">BWI Airport (Penn Line)
</label>
414 <input type=
"radio" required
418 <label for=
"destination_CPK">College Park (Camden Line)
</label>
421 <input type=
"radio" required
425 <label for=
"destination_FRC">Frederick (Brunswick Line)
</label>
428 <input type=
"radio" required
432 <label for=
"destination_HAE">Halethorpe (Penn Line)
</label>
435 <input type=
"radio" required
439 <label for=
"destination_NCR">New Carrollton (Penn Line)
</label>
442 <input type=
"radio" required
446 <label for=
"destination_SEB">Seabrook (Penn Line)
</label>
449 <input type=
"radio" required checked
453 <label for=
"destination_WAS">Washington D.C.
</label>
456 <input type=
"radio" required
460 <label for=
"destination_WBL">West Baltimore (Penn Line)
</label>
463 <p id=
"marc-form-errors">OK
</p>
465 <input type=
"hidden" name=
"serviceid" value=
"R" />
466 <input type=
"hidden" name=
"servicename" value=
"MARC Train" />
470 value=
"Generate Ticket" />
480 * Center the ticket within the browser by translating the SVG
481 * until the ticket and the viewport centerlines coincide.
483 function center_ticket() {
484 /* We're relying on the SVG being the full height of the
485 * viewport already, and on the aspect ratio being
486 * preserved. First, find the center of the ticket. */
487 const r = document.getElementById("ticket").getBoundingClientRect();
488 const c = r.left + (r.width /
2);
490 /* That's the center-line of the ticket. We want to move it to
491 * the center-line of the viewport. */
492 const vc = document.documentElement.clientWidth /
2;
494 /* This is how much we need to translate the SVG */
495 const hdelta = vc - c;
497 /* But before we can set the absolute left-coordinate of the
498 * SVG, we need to know where it is now. Note: without the
499 * "px" this doesn't default to pixels like CSS does. */
500 const svg = document.querySelector("svg");
501 svg.style.left = (svg.getBoundingClientRect().left + hdelta) + "px";
506 * Set the service identifier from the querystring if it's there.
507 * Otherwise, leave it at the default of "F".
509 function set_service_id() {
510 const sid = document.getElementById("serviceid");
512 /* Get the "serviceid" from the querystring if it's there */
513 const params = new URLSearchParams(document.location.search);
514 if (params.get("serviceid")) {
515 sid.textContent = params.get("serviceid");
521 * Set the service name from the querystring if it's there.
522 * Otherwise, leave it at the default of "BaltimoreLink".
524 function set_service_name() {
525 const sid = document.getElementById("servicename");
527 /* Get the "servicename" from the querystring if it's there */
528 const params = new URLSearchParams(document.location.search);
529 if (params.get("servicename")) {
530 sid.textContent = params.get("servicename");
536 * Set the zone from the given "zone" parameter and then unhide it.
538 function set_zone(zone) {
539 const z = document.getElementById("zone");
541 z.textContent = zone;
542 z.style.display = "block"; /* hidden by default */
547 * Resize the ticket background based on the service name.
548 * The BaltimoreLink, Commuter Bus, and MARC Train tickets
549 * are all different heights and are arranged vertically a
552 * Rather than design three completelty separate tickets and
553 * then have to keep track of which one we're using, I have
554 * instead decided to use one ticket and to reposition it
555 * on-the-fly based on the service name. This is necessarily
556 * a bit ugly because it involves a lot of magic numbers that
557 * can only be explained if you open up inkscape with a CharmPass
558 * screenshot to see where things belong and how to get them there.
560 * The SVG was designed with BaltimoreLink in mind, so this
561 * is a no-op if the service is BaltimoreLink.
563 function resize_ticket() {
564 /* Get the "servicename" from the querystring if it's there */
565 const params = new URLSearchParams(document.location.search);
566 const tbg = document.getElementById("ticketbg");
567 const t = document.getElementById("ticket");
568 const sn = document.getElementById("servicename");
570 if (params.get("servicename") === "Commuter Bus") {
571 /* The top of the background is initially at y=
246.859, and
572 * we scale it by a factor of
1.12 to y=
276.482 for a change
573 * of
29.623. So after we scale it, we translate it upwards
574 * by that amount to put it back where it started. */
575 tbg.setAttribute("transform", "translate(
0 -
29.623) scale(
1 1.12)");
577 /* Now translate the entire ticket up by the magic amount,
1/
5
578 * of the size change we made to the background. This ratio
579 * was found by measuring pixels in side-by-side screenshots
580 * of BaltimoreLink and Commuter Bus tickets. */
581 t.setAttribute("transform", "translate(
0 -
9.33)");
583 /* More magic numbers discovered by comparing the two
584 * tickets overlayed in inkscape */
585 sn.setAttribute("transform", "translate(
0 64.28)");
587 else if (params.get("servicename") === "MARC Train") {
588 /* insane tricks are explained above */
589 tbg.setAttribute("transform",
590 "translate(
0 -
72.378) scale(
1 1.2932)");
591 t.setAttribute("transform", "translate(
0 -
67.17)");
592 sn.setAttribute("transform", "translate(
0 131.0)");
598 * Set the security code from the querystring if it was given;
599 * otherwise generate a random code.
601 function set_code() {
602 const ct = document.getElementById("codetext");
604 /* Get the "code" from the querystring if it's there */
605 const params = new URLSearchParams(document.location.search);
606 if (params.get("code")) {
607 ct.textContent = params.get("code").toUpperCase();
610 /* Otherwise, use a random code */
611 const bucket = ["
0","
1","
2","
3","
4","
5","
6","
7","
8","
9",
612 "A","B","C","D","E","F","G","H","I","J",
613 "K","L","M","N","O","P","Q","R","S","T",
614 "U","V","W","X","Y","Z"];
616 /* Two random ints between
0 and
35 */
617 const i1 = Math.floor(Math.random() *
36);
618 const i2 = Math.floor(Math.random() *
36);
619 const d1 = bucket[i1];
620 const d2 = bucket[i2];
621 ct.textContent = d1 + d2;
627 * Center the security code within its container.
629 * Some codes like "II" and "WW" can take up wildly different
630 * amounts of horizonetal space, but they should always be
631 * centered inside their little red box. This turns out to be
632 * harder than it sounds because we can only find the width of
633 * the code in browser coordinates, whereas its "x" coordinate
634 * is in SVG coordinates. Anyway, we do it.
636 function center_code() {
637 /* Center the security code inside its red box */
638 const ct = document.getElementById("codetext");
639 const bg = document.getElementById("codebg");
641 /* First, find the center of the red box */
642 const r1 = bg.getBoundingClientRect();
643 const c1 = r1.left + (r1.width /
2);
645 /* Now the center of the code text */
646 const r2 = ct.getBoundingClientRect();
647 const c2 = r2.left + (r2.width /
2);
649 /* What do we add to c2 to make it equal to c1? */
650 const hdelta = c1 - c2;
652 /* We've measured everything so far in "client rect"
653 * coordinates, because that's the only available measurement
654 * we have for the width of the
<text> element. But when we
655 * reposition that
<text> element, it will be by adjusting its
656 * "x" attribute, and that attribute uses a different coordinate
657 * system than the client rect does. Specifically, "x" refers to
658 * an offset within the SVG's coordinate system, and the client
659 * rect coordinates are pixels on-screen. To convert between the
660 * two, we can take the "width" attribute of the background
661 * element and compare it to the width of the background
662 * element's client rect. Since the size of the background is
663 * fixed, this should give us a multiplier that turns client rect
664 * distances (what we have) into SVG distances (what we want) */
665 const client_to_svg = parseFloat(bg.getAttribute("width"))/r1.width;
667 /* Convert hdelta from client rect to SVG coordinates */
668 const svg_hdelta = hdelta * client_to_svg;
670 /* Since this
<text> element has an "x" attribute it's easier for
671 * us to shift that than it is to mess with the "left" style. */
672 ct.setAttribute("x", parseFloat(ct.getAttribute("x")) + svg_hdelta);
676 * Set the ticket's expiration date and time.
678 * BaltimoreLink and MARC Train tickets expire after
90 minutes;
679 * while Commuter Bus tickets expire after
10 minutes.
681 function set_ticket_expiry() {
682 /* There are two parameters, time and date, that we store in one
683 * underlying "date" variable. */
684 const date = new Date();
686 /* BaltimoreLink and MARC Train */
688 const params = new URLSearchParams(document.location.search);
689 if (params.get("servicename") === "Commuter Bus") {
690 /* Commuter bus tickets are only valid for ten minutes */
694 /* We use the low-level get/setTime to change the number of
695 * milliseconds since the epoch that this date represents
696 * Obviously correct, and avoids all suspicious corner cases
697 * for a few more decades. */
698 date.setTime(date.getTime() + (minutes*
60*
1000));
700 tt = document.getElementById("tickettime");
701 tt.textContent = date.toLocaleTimeString();
703 const td = document.getElementById("ticketdate");
709 td.textContent = date.toLocaleDateString("en-US", dateopts);
714 * Swap the day/night sky colors.
716 * We use CSS classes to keep track of the current state because
717 * it's a tiny bit cleaner than a global variable, but for some
718 * reason we can't use those same classes to actually change the
719 * color. (The classes, change, but the color doesn't.) Rather
720 * than waste time trying to explain this, we just set the "fill"
721 * attribute ourselves whenever we swap classes.
723 function swap_day_night() {
724 const sky = document.getElementById("sky");
726 if (sky.getAttribute("class") === "night") {
727 sky.setAttribute("fill", "#efb02f");
728 sky.setAttribute("class", "day");
731 /* Put this case second so that the first time the
732 * screen is tapped (when there are no classes on
733 * the sky element) the color still changes. */
734 sky.setAttribute("fill", "#
143b66");
735 sky.setAttribute("class", "night");
741 * Compute the zone (string) for the given origin/destination pair.
743 * If we don't know it or if you chose in invalid pair (destination
744 * not on the same line as your origin?) then null is returned.
746 function compute_marc_zone(src, dest) {
748 /* Sorted on the first component, then the second.
791 /* Forward direction key for zone_map */
792 const fwd = src +
"_" + dest;
794 /* Reverse direction key for zone_map. The zone_map only
795 * has them listed in one direction, so we check both
796 * directions here. */
797 const rev = dest +
"_" + src;
799 /* The default. Obviously wrong for when we don't
800 * have the necessary data. */
804 zone = zone_map[fwd];
806 else if (zone_map[rev]) {
807 zone = zone_map[rev];
810 /* Convert the number to a string */
827 * Compute and set the zone.
829 * We can be given a zone in two ways. First, on Commuter Bus
830 * tickets, it is given explicitly via the querystring. But
831 * It can also be specified implicitly via the origin and
832 * destination on a MARC Train ticket. Here we try both and
833 * then call set_zone() with the result if something worked.
835 function compute_and_set_zone() {
836 const params = new URLSearchParams(document.location.search);
837 const src = params.get(
"origin");
838 const dest = params.get(
"destination");
841 /* MARC Train. We can assume that compute_marc_zone() doesn't
842 * return null because that's part of our form validation. */
843 const zone = compute_marc_zone(src, dest);
846 else if (params.get(
"zone")) {
848 set_zone(params.get(
"zone"));
854 * Set the origin and destination for the MARC Train if they
855 * were provided, and unhide them if so.
857 function set_marc_origin_destination() {
858 const params = new URLSearchParams(document.location.search);
859 if (!params.get(
"origin") || !params.get(
"destination")) {
863 const src = params.get(
"origin");
864 const dest = params.get(
"destination");
866 /* origindest contains both the origin and destination */
867 const origindest = document.getElementById(
"origindest");
869 const origin = document.getElementById(
"origin");
870 const destination = document.getElementById(
"destination");
872 origin.textContent = params.get(
"origin");
873 destination.textContent = params.get(
"destination");
875 origindest.style.display =
"block"; /* hidden by default */
880 * Hide the menu and display the ticket. This is what happens
881 * when you submit the form.
884 /* To create our
"window" onto the scene, we're going to slide the
885 * SVG off the left-hand side of the screen, and we don't want
886 * scroll bars to appear. */
887 document.body.style.overflow =
"hidden";
888 document.body.style.margin =
"0";
889 document.body.style.padding =
"0";
891 const svg = document.querySelector(
"svg");
892 const menu = document.getElementById(
"menu");
893 svg.style.display =
"initial";
894 menu.style.display =
"none";
898 * Determine if the user agent is mobile Firefox.
900 function ua_is_mobile_ff() {
901 const ua = navigator.userAgent.toLowerCase();
902 return (ua.includes(
"firefox") && ua.includes(
"mobile"));
906 * Validate the MARC form's origin/destination.
908 * We don't want the user to be able to choose a pair of stops that
909 * aren't actually connected by the same MARC line. If we don't have
910 * zone information for the (origin,destination) pair, that indicates
911 * that it's probably not a valid choice; otherwise I would have
912 * filled in the information from the CharmPass app already.
914 * All browsers except mobile Firefox let us call setCustomValidity()
915 * to provide an error message that is displayed if the user tries
916 * to submit invalid choices. But amazingly, mobile Firefox does not:
918 * https://bugzilla.mozilla.org/show_bug.cgi?id=
1510450
920 * Instead we have to work around it (in that one browser) by
921 * showing/hiding a paragraph that we fill with the errors.
923 function validate_origin_destination(event) {
924 const origins = document.getElementsByName(
"origin");
925 const destinations = document.getElementsByName(
"destination");
926 const mfe = document.getElementById(
"marc-form-errors");
927 const marcsubmit = document.getElementById(
"marc-submit");
929 if (ua_is_mobile_ff()) {
930 /* Even though this is only for one browser, empty paragraphs
931 * are handled inconsistently and should be avoided as a rule.
932 * So, we make it say
"OK" before we hide it. */
933 mfe.textContent =
"OK";
934 mfe.style.visibility =
"hidden";
935 marcsubmit.disabled = false;
940 origins.forEach((x) =
> { if (x.checked) src = x; })
941 destinations.forEach((x) =
> {
942 if (x.checked) dest = x;
944 /* clear all errors before possibly setting one */
945 x.setCustomValidity('');
948 if (src.value === dest.value) {
949 let err = "Origin and destination are the same";
950 dest.setCustomValidity(err);
952 if (ua_is_mobile_ff()) {
953 mfe.textContent = err;
954 mfe.style.visibility = "visible";
955 marcsubmit.disabled = true;
958 else if (compute_marc_zone(src.value, dest.value) === null) {
959 let err = "Origin and destination are on different lines";
960 dest.setCustomValidity(err);
962 if (ua_is_mobile_ff()) {
963 mfe.textContent = err;
964 mfe.style.visibility = "visible";
965 marcsubmit.disabled = true;
970 /*****************************************************/
971 /* Add event handlers for all of the functions above */
972 /*****************************************************/
974 const params = new URLSearchParams(document.location.search);
975 if (params.get("go")) {
976 /* First unhide the SVG (swap it with the form) */
977 window.addEventListener("load", go);
979 /* Center the ticket once when the page has loaded */
980 window.addEventListener("load", center_ticket);
982 /* Re-center the ticket when the window is resized */
983 window.addEventListener("resize", center_ticket);
985 /* Set the service identifier when the page has loaded */
986 window.addEventListener("load", set_service_id);
988 /* Set the service name when the page has loaded */
989 window.addEventListener("load", set_service_name);
991 /* Resize the ticket background if necessary */
992 window.addEventListener("load", resize_ticket);
994 /* Set the security code text when the page has loaded */
995 window.addEventListener("load", set_code);
997 /* Center the security code text when the page has loaded; in
998 * particular, after we set the code. */
999 window.addEventListener("load", center_code);
1001 /* Set the ticket expiration date/time upon page load */
1002 window.addEventListener("load", set_ticket_expiry);
1004 /* Set the MARC Train origin and destination, if applicable */
1005 window.addEventListener("load", set_marc_origin_destination);
1007 /* Compute and set the zone, if applicable */
1008 window.addEventListener("load", compute_and_set_zone);
1010 /* Swap colors when the screen is tapped */
1011 document.body.addEventListener("click", swap_day_night);
1014 /* If we haven't submitted the form yet, set up change handlers
1015 * for the origin/destination radio buttons that validate that
1016 * the origin and destination are on the same line. */
1017 document.getElementsByName("origin").forEach(
1018 (x) =
> x.addEventListener("change", validate_origin_destination)
1020 document.getElementsByName("destination").forEach(
1021 (x) =
> x.addEventListener("change", validate_origin_destination)
1024 /* Also do it when the page loads, because firefox likes to
1025 * remember your selection even after the page reloads. */
1026 window.addEventListener("load", validate_origin_destination);
1028 /* Finally, we have to babysit mobile Firefox, who doesn't
1029 * support HTML5 form validation going into
2024. Turn on
1030 * the little form errors paragraph so we can toggle its
1031 * visibility (and make it display the error) when the user
1032 * makes an invalid selection. */
1033 window.addEventListener("load", () =
> {
1034 if (ua_is_mobile_ff()) {
1035 const mfe = document.getElementById("marc-form-errors");
1036 mfe.style.display = "block";