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
30 /* Set the height to
100% of the screen, which we'll keep; and the
31 * initial position to (
0,
0), which we're going to change
32 * every time the window is resized, because the exact amount
33 * that we have to slide the SVG to the left to get the ticket
34 * into the center will change. */
40 /* Hide everything by default. We only show it once the user has
41 * submitted the menu form */
45 /* The blinking fade in/out animation for the ticket date and time */
58 #tickettime, #ticketdate {
59 /*
300 two-second blinks is ten minutes */
60 animation: blink
2s linear
300;
63 /* Define, load, and specify the custom font we use for the ticket
64 * date, time, and service name. */
66 font-family: "CharmBypass Regular";
68 url("data:font/woff2;base64,@CBPREGULAR@") format("woff2")
71 #origindest, #servicename, #tickettime, #ticketdate, #codetext, #zone {
72 font-family: "CharmBypass Regular", sans-serif;
76 font-family: "CharmBypass Bold";
78 url("data:font/woff2;base64,@CBPBOLD@") format("woff2")
82 font-family: "CharmBypass Bold", sans-serif;
85 /************************/
86 /* Scrolling animations */
87 /************************/
92 transform: translateX(
0%);
95 transform: translateX(-
100%);
100 animation: busroll
23s linear infinite;
105 @keyframes tramroll {
107 transform: translateX(
0%);
110 transform: translateX(
100%);
115 animation: tramroll
17s linear infinite;
120 @keyframes trainroll {
122 transform: translateX(
0%);
125 transform: translateX(
100%);
130 animation: trainroll
11s linear infinite;
135 @keyframes cloudsfloat {
137 transform: translateX(
0%);
140 transform: translateX(-
50%);
145 animation: cloudsfloat
40s linear infinite;
148 @keyframes cloudscopyfloat {
150 transform: translateX(
0%);
153 transform: translateX(-
50%);
158 animation: cloudscopyfloat
40s linear infinite;
163 @keyframes treespass {
165 transform: translateX(
0%);
168 transform: translateX(-
50%);
173 /* The trees move a little faster than the clouds */
174 animation: treespass
30s linear infinite;
177 @keyframes treescopypass {
179 transform: translateX(
0%);
182 transform: translateX(-
50%);
187 /* The trees move a little faster than the clouds */
188 animation: treescopypass
30s linear infinite;
193 @keyframes cityscroll {
195 transform: translateX(
0%);
198 transform: translateX(-
50%);
203 /* The city moves faster than the clouds but slower
205 animation: cityscroll
35s linear infinite;
208 @keyframes citycopyscroll {
210 transform: translateX(
0%);
213 transform: translateX(-
50%);
218 /* The city moves faster than the clouds but slower
220 animation: citycopyscroll
35s linear infinite;
228 <h2>it's transit equity y'all
</h2>
231 <em>Hint:
</em> If you think the driver or fare inspector will
232 actually check it, the daily security code is the same on a
233 $
2.00 BaltimoreLink ticket as it is on a $
9.00 MARC Train
234 ticket. It's also the same on your friend's phone, or for
235 anyone else in Maryland that day.
240 <legend>Local Bus, Light Rail, or Metro
</legend>
243 Daily security code (optional):
251 pattern=
"[a-zA-Z0-9]*" />
253 <input type=
"hidden" name=
"servicename" value=
"BaltimoreLink" />
254 <input type=
"submit" name=
"go" value=
"Generate Ticket" />
259 <legend>Commuter Bus
</legend>
260 <input type=
"hidden" name=
"serviceid" value=
"R" />
261 <input type=
"hidden" name=
"servicename" value=
"Commuter Bus" />
265 Daily security code (optional):
273 pattern=
"[a-zA-Z0-9]*" />
278 <input required
type=
"radio" id=
"zone1" name=
"zone" value=
"Zone 1" />
279 <label for=
"zone1">Zone
1</label>
282 <input required
type=
"radio" id=
"zone2" name=
"zone" value=
"Zone 2" />
283 <label for=
"zone2">Zone
2</label>
286 <input required
type=
"radio" id=
"zone3" name=
"zone" value=
"Zone 3" />
287 <label for=
"zone3">Zone
3</label>
290 <input required
type=
"radio" id=
"zone4" name=
"zone" value=
"Zone 4" />
291 <label for=
"zone4">Zone
4</label>
294 <input required
type=
"radio" id=
"zone5" name=
"zone" value=
"Zone 5" />
295 <label for=
"zone5">Zone
5</label>
298 <input type=
"submit" name=
"go" value=
"Generate Ticket" />
303 <legend>MARC Train
</legend>
307 Daily security code (optional):
315 pattern=
"[a-zA-Z0-9]*" />
320 <input required
type=
"radio" id=
"origin1" name=
"origin" value=
"BAL" />
321 <label for=
"origin1">Baltimore/Penn (Penn Line)
</label>
324 <input required
type=
"radio" id=
"origin2" name=
"origin" value=
"BCA" />
325 <label for=
"origin2">Baltimore/Camden (Camden Line)
</label>
328 <input required
type=
"radio" id=
"origin3" name=
"origin" value=
"BWE" />
329 <label for=
"origin3">Bowie State (Penn Line)
</label>
332 <input required
type=
"radio" id=
"origin4" name=
"origin" value=
"BWI" />
333 <label for=
"origin4">BWI Airport (Penn Line)
</label>
336 <input required
type=
"radio" id=
"origin5" name=
"origin" value=
"CPK" />
337 <label for=
"origin5">College Park (Camden Line)
</label>
340 <input required
type=
"radio" id=
"origin6" name=
"origin" value=
"SEB" />
341 <label for=
"origin6">Seabrook (Penn Line)
</label>
344 <input required
type=
"radio" id=
"origin7" name=
"origin" value=
"WAS" />
345 <label for=
"origin7">Washington D.C.
</label>
348 <input required
type=
"radio" id=
"origin8" name=
"origin" value=
"WBL" />
349 <label for=
"origin8">West Baltimore (Penn Line)
</label>
354 <input required
type=
"radio" id=
"destination1" name=
"destination" value=
"BAL" />
355 <label for=
"destination1">Baltimore/Penn (Penn Line)
</label>
358 <input required
type=
"radio" id=
"destination2" name=
"destination" value=
"BCA" />
359 <label for=
"destination2">Baltimore/Camden (Camden Line)
</label>
362 <input required
type=
"radio" id=
"destination3" name=
"destination" value=
"BWE" />
363 <label for=
"destination3">Bowie State (Penn Line)
</label>
366 <input required
type=
"radio" id=
"destination4" name=
"destination" value=
"BWI" />
367 <label for=
"destination4">BWI Airport (Penn Line)
</label>
370 <input required
type=
"radio" id=
"destination5" name=
"destination" value=
"CPK" />
371 <label for=
"destination5">College Park (Camden Line)
</label>
374 <input required
type=
"radio" id=
"destination6" name=
"destination" value=
"SEB" />
375 <label for=
"destination6">Seabrook (Penn Line)
</label>
378 <input required
type=
"radio" id=
"destination7" name=
"destination" value=
"WAS" />
379 <label for=
"destination7">Washington D.C.
</label>
382 <input required
type=
"radio" id=
"destination8" name=
"destination" value=
"WBL" />
383 <label for=
"destination8">West Baltimore (Penn Line)
</label>
386 <input type=
"hidden" name=
"serviceid" value=
"R" />
387 <input type=
"hidden" name=
"servicename" value=
"MARC Train" />
388 <input type=
"submit" name=
"go" value=
"Generate Ticket" />
397 /***********************************************/
398 /* First, center the ticket within the browser */
399 /***********************************************/
401 function center_ticket() {
402 /* We're relying on the SVG being the full height of the
403 * viewport already, and on the aspect ratio being
404 * preserved. First, find the center of the ticket. */
405 const r = document.getElementById("ticket").getBoundingClientRect();
406 const c = r.left + (r.width /
2);
408 /* That's the center-line of the ticket. We want to move it to
409 * the center-line of the viewport. */
410 const vc = document.documentElement.clientWidth /
2;
412 /* This is how much we need to translate the SVG */
413 const hdelta = vc - c;
415 /* But before we can set the absolute left-coordinate of the
416 * SVG, we need to know where it is now. Note: without the
417 * "px" this doesn't default to pixels like CSS does. */
418 const svg = document.querySelector("svg");
419 svg.style.left = (svg.getBoundingClientRect().left + hdelta) + "px";
423 /******************************/
424 /* Set the service identifier */
425 /******************************/
426 function set_service_id() {
427 const sid = document.getElementById("serviceid");
429 /* Get the "serviceid" from the querystring if it's there */
430 const params = new URLSearchParams(document.location.search);
431 if (params.get("serviceid")) {
432 sid.textContent = params.get("serviceid");
435 /* Otherwise, leave it at "F" */
438 /************************/
439 /* Set the service name */
440 /************************/
441 function set_service_name() {
442 const sid = document.getElementById("servicename");
444 /* Get the "servicename" from the querystring if it's there */
445 const params = new URLSearchParams(document.location.search);
446 if (params.get("servicename")) {
447 sid.textContent = params.get("servicename");
450 /* Otherwise, leave it at "BaltimoreLink" */
454 /************************/
455 /* Set the service zone */
456 /************************/
457 function set_service_zone(event, zone) {
458 /* We can take the zone as a parameter too; this allows us to
459 * use this function for the (computed) MARC Train zone and
460 * not just the querystring Commuter Bus zone. The extra
461 * "event" parameter is there for the event listener, which
462 * would otherwise stuff an onload event into the zone
463 * parameter. "Thankfully" javascript lets us call a
464 * two-argument function with one argument and thereby abuse
465 * the event handler for this. */
466 const z = document.getElementById("zone");
467 const params = new URLSearchParams(document.location.search);
470 z.textContent = zone;
471 z.style.display = "block"; /* It's hidden by default */
473 else if (params.get("zone")) {
474 /* Get the "zone" from the querystring if it's there */
475 z.textContent = params.get("zone");
476 z.style.display = "block"; /* It's hidden by default */
479 /* Otherwise, leave it blank (and hidden) */
482 /***********************************************************/
483 /* Resize the ticket background based on the service name */
484 /***********************************************************/
486 function resize_ticket() {
487 /* Get the "servicename" from the querystring if it's there */
488 const params = new URLSearchParams(document.location.search);
489 const tbg = document.getElementById("ticketbg");
490 const t = document.getElementById("ticket");
491 const sn = document.getElementById("servicename");
493 if (params.get("servicename") == "Commuter Bus") {
494 /* The top of the background is initially at y=
246.859, and
495 * we scale it by a factor of
1.12 to y=
276.482 for a change
496 * of
29.623. So after we scale it, we translate it upwards
497 * by that amount to put it back where it started. */
498 tbg.setAttribute("transform", "translate(
0 -
29.623) scale(
1 1.12)");
500 /* Now translate the entire ticket up by the magic amount,
1/
5
501 * of the size change we made to the background. This ratio
502 * was found by measuring pixels in side-by-side screenshots
503 * of BaltimoreLink and Commuter Bus tickets. */
504 t.setAttribute("transform", "translate(
0 -
9.33)");
506 /* More magic numbers discovered by comparing the two
507 * tickets overlayed in inkscape */
508 sn.setAttribute("transform", "translate(
0 64.28)");
510 else if (params.get("servicename") == "MARC Train") {
511 /* insane tricks are explained above */
512 tbg.setAttribute("transform",
513 "translate(
0 -
72.378) scale(
1 1.2932)");
514 t.setAttribute("transform", "translate(
0 -
67.17)");
515 sn.setAttribute("transform", "translate(
0 131.0)");
518 /* Otherwise, leave it alone. The SVG was designed with the
519 * BaltimoreLink ticket in mind */
522 /****************************************/
523 /* Set and reposition the security code */
524 /****************************************/
526 function set_code() {
527 const ct = document.getElementById("codetext");
529 /* Get the "code" from the querystring if it's there */
530 const params = new URLSearchParams(document.location.search);
531 if (params.get("code")) {
532 ct.textContent = params.get("code").toUpperCase();
535 /* Otherwise, use a random code */
536 const bucket = ["
0","
1","
2","
3","
4","
5","
6","
7","
8","
9",
537 "A","B","C","D","E","F","G","H","I","J",
538 "K","L","M","N","O","P","Q","R","S","T",
539 "U","V","W","X","Y","Z"];
541 /* Two random ints between
0 and
35 */
542 const i1 = Math.floor(Math.random() *
36);
543 const i2 = Math.floor(Math.random() *
36);
544 const d1 = bucket[i1];
545 const d2 = bucket[i2];
546 ct.textContent = d1 + d2;
551 function center_code() {
552 /* Center the security code inside its red box */
553 const ct = document.getElementById("codetext");
554 const bg = document.getElementById("codebg");
556 /* First, find the center of the red box */
557 const r1 = bg.getBoundingClientRect();
558 const c1 = r1.left + (r1.width /
2);
560 /* Now the center of the code text */
561 const r2 = ct.getBoundingClientRect();
562 const c2 = r2.left + (r2.width /
2);
564 /* What do we add to c2 to make it equal to c1? */
565 const hdelta = c1 - c2;
567 /* We've measured everything so far in "client rect"
568 * coordinates, because that's the only available measurement
569 * we have for the width of the
<text> element after futzing
570 * with its contents. But when we reposition that
<text>
571 * element, it will be by adjusting its "x" attribute, and
572 * that attribute uses a different coordinate system than the
573 * client rect does. Specifically, "x" refers to an offset
574 * within the SVG's coordinate system, and the client rect
575 * coordinates are pixels on-screen. To convert between the
576 * two, we can take the "width" attribute of the background
577 * element and compare it to the width of the background
578 * element's client rect. Since the size of the background is
579 * fixed, this should give us a multiplier that turns client recr
580 * distances (what we have) into SVG distances (what we want) */
581 const client_to_svg = parseFloat(bg.getAttribute("width"))/r1.width;
583 /* Convert hdelta from client rect to SVG coordinates */
584 const svg_hdelta = hdelta * client_to_svg;
586 /* Since this
<text> element has an "x" attribute it's easier for
587 * us to shift that than it is to mess with the "left" style. */
588 ct.setAttribute("x", parseFloat(ct.getAttribute("x")) + svg_hdelta);
591 /*****************************************/
592 /* Next, set up the ticket date and time */
593 /*****************************************/
595 function set_ticket_expiry() {
596 /* There are two parameters, time and date, that we store in one
597 * underlying "date" variable. Default both to an hour and a
598 * half from now. This is what the CharmPass app does for
599 * one-way tickets. */
600 const date = new Date();
602 /* BaltimoreLink and MARC Train are valid for an hour and a half */
604 const params = new URLSearchParams(document.location.search);
605 if (params.get("servicename") == "Commuter Bus") {
606 /* But commuter bus tickets are only valid for ten minutes */
610 /* We use the low-level get/setTime to change the number of
611 * milliseconds since the epoch that this date represents
612 * Obviously correct, and avoids all suspicious corner cases
613 * for a few more decades. */
614 date.setTime(date.getTime() + (minutes*
60*
1000));
616 tt = document.getElementById("tickettime");
617 tt.textContent = date.toLocaleTimeString();
619 const td = document.getElementById("ticketdate");
625 td.textContent = date.toLocaleDateString("en-US", dateopts);
629 /*********************************************************/
630 /* Finally, the onclick handler for the night/day switch */
631 /*********************************************************/
633 /* We always start in "day" mode */
637 sky.style.fill = "#efb02f";
640 function set_night() {
641 sky.style.fill = "#
143b66";
644 function swap_colors() {
656 /*******************************************************/
657 /* Compute the MARC "zone" from its origin/destination */
658 /*******************************************************/
660 /* Sorted on the first component, then the second */
674 /* Compute the zone (string) for the given origin/destination pair.
675 * If we don't know it or if you chose in invalid pair (destination
676 * not on the same line as your origin?) then the empty string is
678 function compute_marc_zone(src, dest) {
679 /* Forward direction key for zone_map */
680 const fwd = src + "_" + dest;
682 /* Reverse direction key for zone_map. The zone_map only
683 * has them listed in one direction, so we check both
684 * directions here. */
685 const rev = dest + "_" + src;
687 /* The default. Obviously wrong for when we don't
688 * have the necessary data. */
692 zone = zone_map[fwd];
694 else if (zone_map[rev]) {
695 zone = zone_map[rev];
698 /* Convert the number to a string */
713 function set_marc_zone() {
714 const params = new URLSearchParams(document.location.search);
715 if (params.get("origin") && params.get("destination")) {
716 const src = params.get("origin");
717 const dest = params.get("destination");
718 const zone = compute_marc_zone(src, dest);
720 set_service_zone(null, zone);
725 /*****************************************************/
726 /* Set the origin and destination for the MARC Train */
727 /*****************************************************/
729 function set_marc_origin_destination() {
730 const params = new URLSearchParams(document.location.search);
731 if (!params.get("origin") || !params.get("destination")) {
735 const src = params.get("origin");
736 const dest = params.get("destination");
738 /* origindest contains both the origin and destination */
739 const origindest = document.getElementById("origindest");
741 const origin = document.getElementById("origin");
742 const destination = document.getElementById("destination");
744 origin.textContent = params.get("origin");
745 destination.textContent = params.get("destination");
747 origindest.style.display = "block"; /* It's hidden by default */
750 /******************************************/
751 /* Display the ticket (and hide the menu) */
752 /******************************************/
755 /* To create our "window" onto the scene, we're going to slide the
756 * SVG off the left-hand side of the screen, and we don't want
757 * scroll bars to appear. */
758 document.body.style.overflow = "hidden";
759 document.body.style.margin = "
0";
760 document.body.style.padding = "
0";
762 const svg = document.querySelector("svg");
763 const menu = document.getElementById("menu");
764 svg.style.display = "initial";
765 menu.style.display = "none";
768 /*****************************************************/
769 /* Add event handlers for all of the functions above */
770 /*****************************************************/
772 const params = new URLSearchParams(document.location.search);
773 if (params.get("go")) {
774 /* First unhide the SVG (swap it with the form) */
775 window.addEventListener("load", go);
777 /* Center the ticket once when the page has loaded */
778 window.addEventListener("load", center_ticket);
780 /* Re-center the ticket when the window is resized */
781 window.addEventListener("resize", center_ticket);
783 /* Set the service identifier when the page has loaded */
784 window.addEventListener("load", set_service_id);
786 /* Set the service name when the page has loaded */
787 window.addEventListener("load", set_service_name);
789 /* Set the service zone when the page has loaded */
790 window.addEventListener("load", set_service_zone);
792 /* Resize the ticket background if necessary */
793 window.addEventListener("load", resize_ticket);
795 /* Set the security code text when the page has loaded */
796 window.addEventListener("load", set_code);
798 /* Center the security code text when the page has loaded; in
799 * particular, after we set the code. */
800 window.addEventListener("load", center_code);
802 /* Set the ticket expiration date/time upon page load */
803 window.addEventListener("load", set_ticket_expiry);
805 /* Set the MARC Train origin and destination, if applicable */
806 window.addEventListener("load", set_marc_origin_destination);
808 /* Set the MARC Train zone, if applicable */
809 window.addEventListener("load", set_marc_zone);
811 /* Swap colors when the screen is tapped */
812 document.body.addEventListener("click", swap_colors);