4 <meta name=
"viewport" content=
"width=device-width, initial-scale=1" />
5 <link rel=
"icon" href=
"favicon.svg" />
8 CharmBypass: it's transit equity y'all
24 /* Set the height to
100% of the screen, which we'll keep; and the
25 * initial position to (
0,
0), which we're going to change
26 * every time the window is resized, because the exact amount
27 * that we have to slide the SVG to the left to get the ticket
28 * into the center will change. */
34 /* Hide everything by default. We only show it once the user has
35 * submitted the menu form */
39 /* The blinking fade in/out animation for the ticket date and time */
52 #tickettime, #ticketdate {
53 /*
300 two-second blinks is ten minutes */
54 animation: blink
2s linear
300;
57 /* Define, load, and specify the custom font we use for the ticket
58 * date, time, and service name. */
60 font-family: "CharmBypass Regular";
62 url("data:font/woff2;base64,@CBPREGULAR@") format("woff2")
65 #origindest, #servicename, #tickettime, #ticketdate, #codetext, #zone {
66 font-family: "CharmBypass Regular", sans-serif;
70 font-family: "CharmBypass Bold";
72 url("data:font/woff2;base64,@CBPBOLD@") format("woff2")
76 font-family: "CharmBypass Bold", sans-serif;
79 /************************/
80 /* Scrolling animations */
81 /************************/
86 transform: translateX(
0%);
89 transform: translateX(-
100%);
94 animation: busroll
23s linear infinite;
101 transform: translateX(
0%);
104 transform: translateX(
100%);
109 animation: tramroll
17s linear infinite;
114 @keyframes trainroll {
116 transform: translateX(
0%);
119 transform: translateX(
100%);
124 animation: trainroll
11s linear infinite;
129 @keyframes cloudsfloat {
131 transform: translateX(
0%);
134 transform: translateX(-
50%);
139 animation: cloudsfloat
40s linear infinite;
142 @keyframes cloudscopyfloat {
144 transform: translateX(
0%);
147 transform: translateX(-
50%);
152 animation: cloudscopyfloat
40s linear infinite;
157 @keyframes treespass {
159 transform: translateX(
0%);
162 transform: translateX(-
50%);
167 /* The trees move a little faster than the clouds */
168 animation: treespass
30s linear infinite;
171 @keyframes treescopypass {
173 transform: translateX(
0%);
176 transform: translateX(-
50%);
181 /* The trees move a little faster than the clouds */
182 animation: treescopypass
30s linear infinite;
187 @keyframes cityscroll {
189 transform: translateX(
0%);
192 transform: translateX(-
50%);
197 /* The city moves faster than the clouds but slower
199 animation: cityscroll
35s linear infinite;
202 @keyframes citycopyscroll {
204 transform: translateX(
0%);
207 transform: translateX(-
50%);
212 /* The city moves faster than the clouds but slower
214 animation: citycopyscroll
35s linear infinite;
222 <h2>it's transit equity y'all
</h2>
225 <em>Hint:
</em> If you think the driver or fare inspector will
226 actually check it, the daily security code is the same on a
227 $
2.00 BaltimoreLink ticket as it is on a $
9.00 MARC Train
228 ticket. It's also the same on your friend's phone, or for
229 anyone else in Maryland that day.
234 <legend>BaltimoreLink (Bus, Light Rail, Metro)
</legend>
237 Daily security code (optional):
245 pattern=
"[a-zA-Z0-9]*" />
247 <input type=
"hidden" name=
"servicename" value=
"BaltimoreLink" />
248 <input type=
"submit" name=
"go" value=
"Get Ticket" />
253 <legend>Commuter Bus
</legend>
254 <input type=
"hidden" name=
"serviceid" value=
"R" />
255 <input type=
"hidden" name=
"servicename" value=
"Commuter Bus" />
259 Daily security code (optional):
267 pattern=
"[a-zA-Z0-9]*" />
272 <input required
type=
"radio" id=
"zone1" name=
"zone" value=
"Zone 1" />
273 <label for=
"zone1">Zone
1</label>
276 <input required
type=
"radio" id=
"zone2" name=
"zone" value=
"Zone 2" />
277 <label for=
"zone2">Zone
2</label>
280 <input required
type=
"radio" id=
"zone3" name=
"zone" value=
"Zone 3" />
281 <label for=
"zone3">Zone
3</label>
284 <input required
type=
"radio" id=
"zone4" name=
"zone" value=
"Zone 4" />
285 <label for=
"zone4">Zone
4</label>
288 <input required
type=
"radio" id=
"zone5" name=
"zone" value=
"Zone 5" />
289 <label for=
"zone5">Zone
5</label>
292 <input type=
"submit" name=
"go" value=
"Get Ticket" />
297 <legend>MARC Train
</legend>
301 Daily security code (optional):
309 pattern=
"[a-zA-Z0-9]*" />
315 <input required
type=
"radio" id=
"origin1" name=
"origin" value=
"BAL" />
316 <label for=
"origin1">Baltimore/Penn (Penn Line)
</label>
319 <input required
type=
"radio" id=
"origin2" name=
"origin" value=
"BCA" />
320 <label for=
"origin2">Baltimore/Camden (Camden Line)
</label>
323 <input required
type=
"radio" id=
"origin3" name=
"origin" value=
"BWE" />
324 <label for=
"origin3">Bowie State (Penn Line)
</label>
327 <input required
type=
"radio" id=
"origin4" name=
"origin" value=
"BWI" />
328 <label for=
"origin4">BWI Airport (Penn Line)
</label>
331 <input required
type=
"radio" id=
"origin5" name=
"origin" value=
"CPK" />
332 <label for=
"origin5">College Park (Camden Line)
</label>
335 <input required
type=
"radio" id=
"origin6" name=
"origin" value=
"SEB" />
336 <label for=
"origin6">Seabrook (Penn Line)
</label>
339 <input required
type=
"radio" id=
"origin7" name=
"origin" value=
"WAS" />
340 <label for=
"origin7">Washington D.C.
</label>
343 <input required
type=
"radio" id=
"origin8" name=
"origin" value=
"WBL" />
344 <label for=
"origin8">West Baltimore (Penn Line)
</label>
349 <input required
type=
"radio" id=
"destination1" name=
"destination" value=
"BAL" />
350 <label for=
"destination1">Baltimore/Penn (Penn Line)
</label>
353 <input required
type=
"radio" id=
"destination2" name=
"destination" value=
"BCA" />
354 <label for=
"destination2">Baltimore/Camden (Camden Line)
</label>
357 <input required
type=
"radio" id=
"destination3" name=
"destination" value=
"BWE" />
358 <label for=
"destination3">Bowie State (Penn Line)
</label>
361 <input required
type=
"radio" id=
"destination4" name=
"destination" value=
"BWI" />
362 <label for=
"destination4">BWI Airport (Penn Line)
</label>
365 <input required
type=
"radio" id=
"destination5" name=
"destination" value=
"CPK" />
366 <label for=
"destination5">College Park (Camden Line)
</label>
369 <input required
type=
"radio" id=
"destination6" name=
"destination" value=
"SEB" />
370 <label for=
"destination6">Seabrook (Penn Line)
</label>
373 <input required
type=
"radio" id=
"destination7" name=
"destination" value=
"WAS" />
374 <label for=
"destination7">Washington D.C.
</label>
377 <input required
type=
"radio" id=
"destination8" name=
"destination" value=
"WBL" />
378 <label for=
"destination8">West Baltimore (Penn Line)
</label>
381 <input type=
"hidden" name=
"serviceid" value=
"R" />
382 <input type=
"hidden" name=
"servicename" value=
"MARC Train" />
383 <input type=
"submit" name=
"go" value=
"Get Ticket" />
392 /***********************************************/
393 /* First, center the ticket within the browser */
394 /***********************************************/
396 function center_ticket() {
397 /* We're relying on the SVG being the full height of the
398 * viewport already, and on the aspect ratio being
399 * preserved. First, find the center of the ticket. */
400 const r = document.getElementById("ticket").getBoundingClientRect();
401 const c = r.left + (r.width /
2);
403 /* That's the center-line of the ticket. We want to move it to
404 * the center-line of the viewport. */
405 const vc = document.documentElement.clientWidth /
2;
407 /* This is how much we need to translate the SVG */
408 const hdelta = vc - c;
410 /* But before we can set the absolute left-coordinate of the
411 * SVG, we need to know where it is now. Note: without the
412 * "px" this doesn't default to pixels like CSS does. */
413 const svg = document.querySelector("svg");
414 svg.style.left = (svg.getBoundingClientRect().left + hdelta) + "px";
418 /******************************/
419 /* Set the service identifier */
420 /******************************/
421 function set_service_id() {
422 const sid = document.getElementById("serviceid");
424 /* Get the "serviceid" from the querystring if it's there */
425 const params = new URLSearchParams(document.location.search);
426 if (params.get("serviceid")) {
427 sid.textContent = params.get("serviceid");
430 /* Otherwise, leave it at "F" */
433 /************************/
434 /* Set the service name */
435 /************************/
436 function set_service_name() {
437 const sid = document.getElementById("servicename");
439 /* Get the "servicename" from the querystring if it's there */
440 const params = new URLSearchParams(document.location.search);
441 if (params.get("servicename")) {
442 sid.textContent = params.get("servicename");
445 /* Otherwise, leave it at "BaltimoreLink" */
449 /************************/
450 /* Set the service zone */
451 /************************/
452 function set_service_zone(event, zone) {
453 /* We can take the zone as a parameter too; this allows us to
454 * use this function for the (computed) MARC Train zone and
455 * not just the querystring Commuter Bus zone. The extra
456 * "event" parameter is there for the event listener, which
457 * would otherwise stuff an onload event into the zone
458 * parameter. "Thankfully" javascript lets us call a
459 * two-argument function with one argument and thereby abuse
460 * the event handler for this. */
461 const z = document.getElementById("zone");
462 const params = new URLSearchParams(document.location.search);
465 z.textContent = zone;
466 z.style.display = "block"; /* It's hidden by default */
468 else if (params.get("zone")) {
469 /* Get the "zone" from the querystring if it's there */
470 z.textContent = params.get("zone");
471 z.style.display = "block"; /* It's hidden by default */
474 /* Otherwise, leave it blank (and hidden) */
477 /***********************************************************/
478 /* Resize the ticket background based on the service name */
479 /***********************************************************/
481 function resize_ticket() {
482 /* Get the "servicename" from the querystring if it's there */
483 const params = new URLSearchParams(document.location.search);
484 const tbg = document.getElementById("ticketbg");
485 const t = document.getElementById("ticket");
486 const sn = document.getElementById("servicename");
488 if (params.get("servicename") == "Commuter Bus") {
489 /* The top of the background is initially at y=
246.859, and
490 * we scale it by a factor of
1.12 to y=
276.482 for a change
491 * of
29.623. So after we scale it, we translate it upwards
492 * by that amount to put it back where it started. */
493 tbg.setAttribute("transform", "translate(
0 -
29.623) scale(
1 1.12)");
495 /* Now translate the entire ticket up by the magic amount,
1/
5
496 * of the size change we made to the background. This ratio
497 * was found by measuring pixels in side-by-side screenshots
498 * of BaltimoreLink and Commuter Bus tickets. */
499 t.setAttribute("transform", "translate(
0 -
9.33)");
501 /* More magic numbers discovered by comparing the two
502 * tickets overlayed in inkscape */
503 sn.setAttribute("transform", "translate(
0 64.28)");
505 else if (params.get("servicename") == "MARC Train") {
506 /* insane tricks are explained above */
507 tbg.setAttribute("transform",
508 "translate(
0 -
72.378) scale(
1 1.2932)");
509 t.setAttribute("transform", "translate(
0 -
67.17)");
510 sn.setAttribute("transform", "translate(
0 131.0)");
513 /* Otherwise, leave it alone. The SVG was designed with the
514 * BaltimoreLink ticket in mind */
517 /****************************************/
518 /* Set and reposition the security code */
519 /****************************************/
521 function set_code() {
522 const ct = document.getElementById("codetext");
524 /* Get the "code" from the querystring if it's there */
525 const params = new URLSearchParams(document.location.search);
526 if (params.get("code")) {
527 ct.textContent = params.get("code").toUpperCase();
530 /* Otherwise, use a random code */
531 const bucket = ["
0","
1","
2","
3","
4","
5","
6","
7","
8","
9",
532 "A","B","C","D","E","F","G","H","I","J",
533 "K","L","M","N","O","P","Q","R","S","T",
534 "U","V","W","X","Y","Z"];
536 /* Two random ints between
0 and
35 */
537 const i1 = Math.floor(Math.random() *
36);
538 const i2 = Math.floor(Math.random() *
36);
539 const d1 = bucket[i1];
540 const d2 = bucket[i2];
541 ct.textContent = d1 + d2;
546 function center_code() {
547 /* Center the security code inside its red box */
548 const ct = document.getElementById("codetext");
549 const bg = document.getElementById("codebg");
551 /* First, find the center of the red box */
552 const r1 = bg.getBoundingClientRect();
553 const c1 = r1.left + (r1.width /
2);
555 /* Now the center of the code text */
556 const r2 = ct.getBoundingClientRect();
557 const c2 = r2.left + (r2.width /
2);
559 /* What do we add to c2 to make it equal to c1? */
560 const hdelta = c1 - c2;
562 /* We've measured everything so far in "client rect"
563 * coordinates, because that's the only available measurement
564 * we have for the width of the
<text> element after futzing
565 * with its contents. But when we reposition that
<text>
566 * element, it will be by adjusting its "x" attribute, and
567 * that attribute uses a different coordinate system than the
568 * client rect does. Specifically, "x" refers to an offset
569 * within the SVG's coordinate system, and the client rect
570 * coordinates are pixels on-screen. To convert between the
571 * two, we can take the "width" attribute of the background
572 * element and compare it to the width of the background
573 * element's client rect. Since the size of the background is
574 * fixed, this should give us a multiplier that turns client recr
575 * distances (what we have) into SVG distances (what we want) */
576 const client_to_svg = parseFloat(bg.getAttribute("width"))/r1.width;
578 /* Convert hdelta from client rect to SVG coordinates */
579 const svg_hdelta = hdelta * client_to_svg;
581 /* Since this
<text> element has an "x" attribute it's easier for
582 * us to shift that than it is to mess with the "left" style. */
583 ct.setAttribute("x", parseFloat(ct.getAttribute("x")) + svg_hdelta);
586 /*****************************************/
587 /* Next, set up the ticket date and time */
588 /*****************************************/
590 function set_ticket_expiry() {
591 /* There are two parameters, time and date, that we store in one
592 * underlying "date" variable. Default both to an hour and a
593 * half from now. This is what the CharmPass app does for
594 * one-way tickets. */
595 const date = new Date();
597 /* BaltimoreLink and MARC Train are valid for an hour and a half */
599 const params = new URLSearchParams(document.location.search);
600 if (params.get("servicename") == "Commuter Bus") {
601 /* But commuter bus tickets are only valid for ten minutes */
605 /* We use the low-level get/setTime to change the number of
606 * milliseconds since the epoch that this date represents
607 * Obviously correct, and avoids all suspicious corner cases
608 * for a few more decades. */
609 date.setTime(date.getTime() + (minutes*
60*
1000));
611 tt = document.getElementById("tickettime");
612 tt.textContent = date.toLocaleTimeString();
614 const td = document.getElementById("ticketdate");
620 td.textContent = date.toLocaleDateString("en-US", dateopts);
624 /*********************************************************/
625 /* Finally, the onclick handler for the night/day switch */
626 /*********************************************************/
628 /* We always start in "day" mode */
632 sky.style.fill = "#efb02f";
635 function set_night() {
636 sky.style.fill = "#
143b66";
639 function swap_colors() {
651 /*******************************************************/
652 /* Compute the MARC "zone" from its origin/destination */
653 /*******************************************************/
655 /* Sorted on the first component, then the second */
669 /* Compute the zone (string) for the given origin/destination pair.
670 * If we don't know it or if you chose in invalid pair (destination
671 * not on the same line as your origin?) then the empty string is
673 function compute_marc_zone(src, dest) {
674 /* Forward direction key for zone_map */
675 const fwd = src + "_" + dest;
677 /* Reverse direction key for zone_map. The zone_map only
678 * has them listed in one direction, so we check both
679 * directions here. */
680 const rev = dest + "_" + src;
682 /* The default. Obviously wrong for when we don't
683 * have the necessary data. */
687 zone = zone_map[fwd];
689 else if (zone_map[rev]) {
690 zone = zone_map[rev];
693 /* Convert the number to a string */
708 function set_marc_zone() {
709 const params = new URLSearchParams(document.location.search);
710 if (params.get("origin") && params.get("destination")) {
711 const src = params.get("origin");
712 const dest = params.get("destination");
713 const zone = compute_marc_zone(src, dest);
715 set_service_zone(null, zone);
720 /*****************************************************/
721 /* Set the origin and destination for the MARC Train */
722 /*****************************************************/
724 function set_marc_origin_destination() {
725 const params = new URLSearchParams(document.location.search);
726 if (!params.get("origin") || !params.get("destination")) {
730 const src = params.get("origin");
731 const dest = params.get("destination");
733 /* origindest contains both the origin and destination */
734 const origindest = document.getElementById("origindest");
736 const origin = document.getElementById("origin");
737 const destination = document.getElementById("destination");
739 origin.textContent = params.get("origin");
740 destination.textContent = params.get("destination");
742 origindest.style.display = "block"; /* It's hidden by default */
745 /******************************************/
746 /* Display the ticket (and hide the menu) */
747 /******************************************/
750 /* To create our "window" onto the scene, we're going to slide the
751 * SVG off the left-hand side of the screen, and we don't want
752 * scroll bars to appear. */
753 document.body.style.overflow = "hidden";
754 document.body.style.margin = "
0";
755 document.body.style.padding = "
0";
757 const svg = document.querySelector("svg");
758 const menu = document.getElementById("menu");
759 svg.style.display = "initial";
760 menu.style.display = "none";
763 /*****************************************************/
764 /* Add event handlers for all of the functions above */
765 /*****************************************************/
767 const params = new URLSearchParams(document.location.search);
768 if (params.get("go")) {
769 /* First unhide the SVG (swap it with the form) */
770 window.addEventListener("load", go);
772 /* Center the ticket once when the page has loaded */
773 window.addEventListener("load", center_ticket);
775 /* Re-center the ticket when the window is resized */
776 window.addEventListener("resize", center_ticket);
778 /* Set the service identifier when the page has loaded */
779 window.addEventListener("load", set_service_id);
781 /* Set the service name when the page has loaded */
782 window.addEventListener("load", set_service_name);
784 /* Set the service zone when the page has loaded */
785 window.addEventListener("load", set_service_zone);
787 /* Resize the ticket background if necessary */
788 window.addEventListener("load", resize_ticket);
790 /* Set the security code text when the page has loaded */
791 window.addEventListener("load", set_code);
793 /* Center the security code text when the page has loaded; in
794 * particular, after we set the code. */
795 window.addEventListener("load", center_code);
797 /* Set the ticket expiration date/time upon page load */
798 window.addEventListener("load", set_ticket_expiry);
800 /* Set the MARC Train origin and destination, if applicable */
801 window.addEventListener("load", set_marc_origin_destination);
803 /* Set the MARC Train zone, if applicable */
804 window.addEventListener("load", set_marc_zone);
806 /* Swap colors when the screen is tapped */
807 document.body.addEventListener("click", swap_colors);