5 <meta name=
"viewport" content=
"width=device-width, initial-scale=1" />
8 href=
"data:image/svg+xml;base64,@FAVICON@" />
11 CharmBypass: it's transit equity y'all
16 /* For consistency with the SVG */
17 font-family: sans-serif;
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. */
45 /* Hide everything by default. We only show it once the user has
46 * submitted the menu form */
50 /* The blinking fade in/out animation for the ticket date and time */
57 #tickettime, #ticketdate {
58 /*
300 two-second blinks is ten minutes */
59 animation: blink
2s linear
300;
62 /* Define, load, and specify the custom font we use for the ticket
63 * date, time, and service name. */
65 font-family: "CharmBypass Regular";
67 url("data:font/woff2;base64,@CBPREGULAR@") format("woff2")
70 #origindest, #servicename, #tickettime, #ticketdate, #codetext, #zone {
71 font-family: "CharmBypass Regular", sans-serif;
75 font-family: "CharmBypass Bold";
77 url("data:font/woff2;base64,@CBPBOLD@") format("woff2")
81 font-family: "CharmBypass Bold", sans-serif;
84 /************************/
85 /* Scrolling animations */
86 /************************/
90 from { transform: translateX(
0%); }
91 to { transform: translateX(-
100%); }
95 animation: busroll
23s linear infinite;
100 @keyframes tramroll {
101 from { transform: translateX(
0%); }
102 to { transform: translateX(
100%); }
106 animation: tramroll
17s linear infinite;
111 @keyframes trainroll {
112 from { transform: translateX(
0%); }
113 to { transform: translateX(
100%); }
117 animation: trainroll
11s linear infinite;
122 @keyframes cloudsfloat {
123 from { transform: translateX(
0%); }
124 to { transform: translateX(-
50%); }
128 animation: cloudsfloat
40s linear infinite;
131 @keyframes cloudscopyfloat {
132 from { transform: translateX(
0%); }
133 to { transform: translateX(-
50%); }
137 animation: cloudscopyfloat
40s linear infinite;
142 @keyframes treespass {
143 from { transform: translateX(
0%); }
144 to { transform: translateX(-
50%); }
148 /* The trees move a little faster than the clouds */
149 animation: treespass
30s linear infinite;
152 @keyframes treescopypass {
153 from { transform: translateX(
0%); }
154 to { transform: translateX(-
50%); }
158 /* The trees move a little faster than the clouds */
159 animation: treescopypass
30s linear infinite;
164 @keyframes cityscroll {
165 from { transform: translateX(
0%); }
166 to { transform: translateX(-
50%); }
170 /* The city moves faster than the clouds but slower
172 animation: cityscroll
35s linear infinite;
175 @keyframes citycopyscroll {
176 from { transform: translateX(
0%); }
177 to { transform: translateX(-
50%); }
181 /* The city moves faster than the clouds but slower
183 animation: citycopyscroll
35s linear infinite;
191 <h2>it's transit equity y'all
</h2>
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.
201 <legend>Local Bus, Light Rail, or Metro
</legend>
204 Daily security code (optional):
212 pattern=
"[a-zA-Z0-9]*" />
214 <input type=
"hidden" name=
"servicename" value=
"BaltimoreLink" />
215 <input type=
"submit" name=
"go" value=
"Generate Ticket" />
220 <legend>Commuter Bus
</legend>
221 <input type=
"hidden" name=
"serviceid" value=
"R" />
222 <input type=
"hidden" name=
"servicename" value=
"Commuter Bus" />
226 Daily security code (optional):
234 pattern=
"[a-zA-Z0-9]*" />
239 <input type=
"radio" required
243 <label for=
"zone1">Zone
1</label>
246 <input type=
"radio" required
250 <label for=
"zone2">Zone
2</label>
253 <input type=
"radio" required checked
257 <label for=
"zone3">Zone
3</label>
260 <input type=
"radio" required
264 <label for=
"zone4">Zone
4</label>
267 <input type=
"radio" required
271 <label for=
"zone5">Zone
5</label>
274 <input type=
"submit" name=
"go" value=
"Generate Ticket" />
279 <legend>MARC Train
</legend>
283 Daily security code (optional):
291 pattern=
"[a-zA-Z0-9]*" />
296 <input type=
"radio" required checked
300 <label for=
"origin1">Baltimore/Penn (Penn Line)
</label>
303 <input type=
"radio" required
307 <label for=
"origin2">Baltimore/Camden (Camden Line)
</label>
310 <input type=
"radio" required
314 <label for=
"origin3">Bowie State (Penn Line)
</label>
317 <input type=
"radio" required
321 <label for=
"origin4">BWI Airport (Penn Line)
</label>
324 <input type=
"radio" required
328 <label for=
"origin5">College Park (Camden Line)
</label>
331 <input type=
"radio" required
335 <label for=
"origin6">Seabrook (Penn Line)
</label>
338 <input type=
"radio" required
342 <label for=
"origin7">Washington D.C.
</label>
345 <input type=
"radio" required
349 <label for=
"origin8">West Baltimore (Penn Line)
</label>
354 <input type=
"radio" required
358 <label for=
"destination1">Baltimore/Penn (Penn Line)
</label>
361 <input type=
"radio" required
365 <label for=
"destination2">Baltimore/Camden (Camden Line)
</label>
368 <input type=
"radio" required
372 <label for=
"destination3">Bowie State (Penn Line)
</label>
375 <input type=
"radio" required
379 <label for=
"destination4">BWI Airport (Penn Line)
</label>
382 <input type=
"radio" required
386 <label for=
"destination5">College Park (Camden Line)
</label>
389 <input type=
"radio" required
393 <label for=
"destination6">Seabrook (Penn Line)
</label>
396 <input type=
"radio" required checked
400 <label for=
"destination7">Washington D.C.
</label>
403 <input type=
"radio" required
407 <label for=
"destination8">West Baltimore (Penn Line)
</label>
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" />
422 * Center the ticket within the browser by translating the SVG
423 * until the ticket and the viewport centerlines coincide.
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);
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;
436 /* This is how much we need to translate the SVG */
437 const hdelta = vc - c;
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";
448 * Set the service identifier from the querystring if it's there.
449 * Otherwise, leave it at the default of "F".
451 function set_service_id() {
452 const sid = document.getElementById("serviceid");
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");
463 * Set the service name from the querystring if it's there.
464 * Otherwise, leave it at the default of "BaltimoreLink".
466 function set_service_name() {
467 const sid = document.getElementById("servicename");
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");
478 * Set the zone from the given "zone" parameter and then unhide it.
480 function set_zone(zone) {
481 const z = document.getElementById("zone");
483 z.textContent = zone;
484 z.style.display = "block"; /* hidden by default */
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
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.
502 * The SVG was designed with BaltimoreLink in mind, so this
503 * is a no-op if the service is BaltimoreLink.
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");
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)");
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)");
525 /* More magic numbers discovered by comparing the two
526 * tickets overlayed in inkscape */
527 sn.setAttribute("transform", "translate(
0 64.28)");
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)");
540 * Set the security code from the querystring if it was given;
541 * otherwise generate a random code.
543 function set_code() {
544 const ct = document.getElementById("codetext");
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();
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"];
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;
569 * Center the security code within its container.
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.
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");
583 /* First, find the center of the red box */
584 const r1 = bg.getBoundingClientRect();
585 const c1 = r1.left + (r1.width /
2);
587 /* Now the center of the code text */
588 const r2 = ct.getBoundingClientRect();
589 const c2 = r2.left + (r2.width /
2);
591 /* What do we add to c2 to make it equal to c1? */
592 const hdelta = c1 - c2;
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;
609 /* Convert hdelta from client rect to SVG coordinates */
610 const svg_hdelta = hdelta * client_to_svg;
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);
618 * Set the ticket's expiration date and time.
620 * BaltimoreLink and MARC Train tickets expire after
90 minutes;
621 * while Commuter Bus tickets expire after
10 minutes.
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();
628 /* BaltimoreLink and MARC Train */
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 */
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));
642 tt = document.getElementById("tickettime");
643 tt.textContent = date.toLocaleTimeString();
645 const td = document.getElementById("ticketdate");
651 td.textContent = date.toLocaleDateString("en-US", dateopts);
656 * Swap the day/night sky colors.
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.
665 function swap_day_night() {
666 const sky = document.getElementById("sky");
668 if (sky.getAttribute("class") === "night") {
669 sky.setAttribute("fill", "#efb02f");
670 sky.setAttribute("class", "day");
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");
683 * Compute the zone (string) for the given origin/destination pair.
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.
688 function compute_marc_zone(src, dest) {
690 /* Sorted on the first component, then the second */
707 /* Forward direction key for zone_map */
708 const fwd = src + "_" + dest;
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;
715 /* The default. Obviously wrong for when we don't
716 * have the necessary data. */
720 zone = zone_map[fwd];
722 else if (zone_map[rev]) {
723 zone = zone_map[rev];
726 /* Convert the number to a string */
743 * Compute and set the zone.
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.
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");
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);
762 else if (params.get("zone")) {
764 set_zone(params.get("zone"));
770 * Set the origin and destination for the MARC Train if they
771 * were provided, and unhide them if so.
773 function set_marc_origin_destination() {
774 const params = new URLSearchParams(document.location.search);
775 if (!params.get("origin") || !params.get("destination")) {
779 const src = params.get("origin");
780 const dest = params.get("destination");
782 /* origindest contains both the origin and destination */
783 const origindest = document.getElementById("origindest");
785 const origin = document.getElementById("origin");
786 const destination = document.getElementById("destination");
788 origin.textContent = params.get("origin");
789 destination.textContent = params.get("destination");
791 origindest.style.display = "block"; /* hidden by default */
796 * Hide the menu and display the ticket. This is what happens
797 * when you submit the form.
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";
807 const svg = document.querySelector("svg");
808 const menu = document.getElementById("menu");
809 svg.style.display = "initial";
810 menu.style.display = "none";
814 * Validate the MARC form's origin/destination.
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.
822 function validate_origin_destination(event) {
823 const origins = document.getElementsByName("origin");
824 const destinations = document.getElementsByName("destination");
828 origins.forEach((x) =
> { if (x.checked) src = x; })
829 destinations.forEach((x) =
> {
830 if (x.checked) dest = x;
832 /* clear all errors before possibly setting one */
833 x.setCustomValidity('');
836 if (src.value === dest.value) {
837 let err = "Origin and destination are the same!";
838 dest.setCustomValidity(err);
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);
846 /*****************************************************/
847 /* Add event handlers for all of the functions above */
848 /*****************************************************/
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);
855 /* Center the ticket once when the page has loaded */
856 window.addEventListener("load", center_ticket);
858 /* Re-center the ticket when the window is resized */
859 window.addEventListener("resize", center_ticket);
861 /* Set the service identifier when the page has loaded */
862 window.addEventListener("load", set_service_id);
864 /* Set the service name when the page has loaded */
865 window.addEventListener("load", set_service_name);
867 /* Resize the ticket background if necessary */
868 window.addEventListener("load", resize_ticket);
870 /* Set the security code text when the page has loaded */
871 window.addEventListener("load", set_code);
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);
877 /* Set the ticket expiration date/time upon page load */
878 window.addEventListener("load", set_ticket_expiry);
880 /* Set the MARC Train origin and destination, if applicable */
881 window.addEventListener("load", set_marc_origin_destination);
883 /* Compute and set the zone, if applicable */
884 window.addEventListener("load", compute_and_set_zone);
886 /* Swap colors when the screen is tapped */
887 document.body.addEventListener("click", swap_day_night);
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)
896 document.getElementsByName("destination").forEach(
897 (x) =
> x.addEventListener("change", validate_origin_destination)
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);