4 <meta name=
"viewport" content=
"width=device-width, initial-scale=1" />
7 CharmBypass: you're getting transit equity whether you like it
18 /* Set the height to
100% of the screen, which we'll keep; and the
19 * initial position to (
0,
0), which we're going to change
20 * every time the window is resized, because the exact amount
21 * that we have to slide the SVG to the left to get the ticket
22 * into the center will change. */
28 /* Hide everything by default. We only show it once the user has
29 * submitted the menu form */
33 /* The blinking fade in/out animation for the ticket date and time */
46 #tickettime, #ticketdate {
47 /*
300 two-second blinks is ten minutes */
48 animation: blink
2s linear
300;
51 /* Define, load, and specify the custom font we use for the ticket
52 * date, time, and service name. */
54 font-family: "CharmBypass Regular";
56 url("data:font/woff2;base64,@CBPREGULAR@") format("woff2")
59 #servicename, #tickettime, #ticketdate, #codetext {
60 font-family: "CharmBypass Regular", sans-serif;
64 font-family: "CharmBypass Bold";
66 url("data:font/woff2;base64,@CBPBOLD@") format("woff2")
70 font-family: "CharmBypass Bold", sans-serif;
74 /************************/
75 /* Scrolling animations */
76 /************************/
81 transform: translateX(
0%);
84 transform: translateX(-
100%);
89 animation: busroll
23s linear infinite;
96 transform: translateX(
0%);
99 transform: translateX(
100%);
104 animation: tramroll
17s linear infinite;
109 @keyframes trainroll {
111 transform: translateX(
0%);
114 transform: translateX(
100%);
119 animation: trainroll
11s linear infinite;
124 @keyframes cloudsfloat {
126 transform: translateX(
0%);
129 transform: translateX(-
50%);
134 animation: cloudsfloat
40s linear infinite;
137 @keyframes cloudscopyfloat {
139 transform: translateX(
0%);
142 transform: translateX(-
50%);
147 animation: cloudscopyfloat
40s linear infinite;
152 @keyframes treespass {
154 transform: translateX(
0%);
157 transform: translateX(-
50%);
162 /* The trees move a little faster than the clouds */
163 animation: treespass
30s linear infinite;
166 @keyframes treescopypass {
168 transform: translateX(
0%);
171 transform: translateX(-
50%);
176 /* The trees move a little faster than the clouds */
177 animation: treescopypass
30s linear infinite;
182 @keyframes cityscroll {
184 transform: translateX(
0%);
187 transform: translateX(-
50%);
192 /* The city moves faster than the clouds but slower
194 animation: cityscroll
35s linear infinite;
197 @keyframes citycopyscroll {
199 transform: translateX(
0%);
202 transform: translateX(-
50%);
207 /* The city moves faster than the clouds but slower
209 animation: citycopyscroll
35s linear infinite;
217 <h2>you're getting transit equity whether you like it or not
</h2>
220 <legend>BaltimoreLink (Bus, Light Rail, Metro)
</legend>
223 Daily security code (optional):
230 pattern=
"[a-zA-Z0-9]+" />
232 <input type=
"hidden" name=
"servicename" value=
"BaltimoreLink" />
233 <input type=
"submit" name=
"go" value=
"Get Ticket" />
238 <legend>Commuter Bus
</legend>
239 <input type=
"hidden" name=
"serviceid" value=
"R" />
240 <input type=
"hidden" name=
"servicename" value=
"Commuter Bus" />
244 Daily security code (optional):
251 pattern=
"[a-zA-Z0-9]+" />
256 <input required
type=
"radio" id=
"zone1" name=
"zone" value=
"Zone 1" />
257 <label for=
"zone1">Zone
1</label>
260 <input required
type=
"radio" id=
"zone2" name=
"zone" value=
"Zone 2" />
261 <label for=
"zone2">Zone
2</label>
264 <input required
type=
"radio" id=
"zone3" name=
"zone" value=
"Zone 3" />
265 <label for=
"zone3">Zone
3</label>
268 <input required
type=
"radio" id=
"zone4" name=
"zone" value=
"Zone 4" />
269 <label for=
"zone4">Zone
4</label>
272 <input required
type=
"radio" id=
"zone5" name=
"zone" value=
"Zone 5" />
273 <label for=
"zone5">Zone
5</label>
276 <input type=
"submit" name=
"go" value=
"Get Ticket" />
281 <legend>MARC Train
</legend>
285 Daily security code (optional):
292 pattern=
"[a-zA-Z0-9]+" />
298 <input required
type=
"radio" id=
"origin1" name=
"origin" value=
"BAL" />
299 <label for=
"origin1">Baltimore/Penn (Penn Line)
</label>
302 <input required
type=
"radio" id=
"origin2" name=
"origin" value=
"BCA" />
303 <label for=
"origin2">Baltimore/Camden (Camden Line)
</label>
306 <input required
type=
"radio" id=
"origin3" name=
"origin" value=
"BWE" />
307 <label for=
"origin3">Bowie State (Penn Line)
</label>
310 <input required
type=
"radio" id=
"origin4" name=
"origin" value=
"BWI" />
311 <label for=
"origin4">BWI Airport (Penn Line)
</label>
314 <input required
type=
"radio" id=
"origin5" name=
"origin" value=
"CPK" />
315 <label for=
"origin5">College Park (Camden Line)
</label>
318 <input required
type=
"radio" id=
"origin6" name=
"origin" value=
"SEB" />
319 <label for=
"origin6">Seabrook (Penn Line)
</label>
322 <input required
type=
"radio" id=
"origin7" name=
"origin" value=
"WAS" />
323 <label for=
"origin7">Washington D.C.
</label>
326 <input required
type=
"radio" id=
"origin8" name=
"origin" value=
"WBL" />
327 <label for=
"origin8">West Baltimore (Penn Line)
</label>
332 <input required
type=
"radio" id=
"destination1" name=
"destination" value=
"BAL" />
333 <label for=
"destination1">Baltimore/Penn (Penn Line)
</label>
336 <input required
type=
"radio" id=
"destination2" name=
"destination" value=
"BCA" />
337 <label for=
"destination2">Baltimore/Camden (Camden Line)
</label>
340 <input required
type=
"radio" id=
"destination3" name=
"destination" value=
"BWE" />
341 <label for=
"destination3">Bowie State (Penn Line)
</label>
344 <input required
type=
"radio" id=
"destination4" name=
"destination" value=
"BWI" />
345 <label for=
"destination4">BWI Airport (Penn Line)
</label>
348 <input required
type=
"radio" id=
"destination5" name=
"destination" value=
"CPK" />
349 <label for=
"destination5">College Park (Camden Line)
</label>
352 <input required
type=
"radio" id=
"destination6" name=
"destination" value=
"SEB" />
353 <label for=
"destination6">Seabrook (Penn Line)
</label>
356 <input required
type=
"radio" id=
"destination7" name=
"destination" value=
"WAS" />
357 <label for=
"destination7">Washington D.C.
</label>
360 <input required
type=
"radio" id=
"destination8" name=
"destination" value=
"WBL" />
361 <label for=
"destination8">West Baltimore (Penn Line)
</label>
364 <input type=
"hidden" name=
"serviceid" value=
"R" />
365 <input type=
"hidden" name=
"servicename" value=
"MARC Train" />
366 <input type=
"submit" name=
"go" value=
"Get Ticket" />
375 /***********************************************/
376 /* First, center the ticket within the browser */
377 /***********************************************/
379 function center_ticket() {
380 /* We're relying on the SVG being the full height of the
381 * viewport already, and on the aspect ratio being
382 * preserved. First, find the center of the ticket. */
383 const r = document.getElementById("ticket").getBoundingClientRect();
384 const c = r.left + (r.width /
2);
386 /* That's the center-line of the ticket. We want to move it to
387 * the center-line of the viewport. */
388 const vc = document.documentElement.clientWidth /
2;
390 /* This is how much we need to translate the SVG */
391 const hdelta = vc - c;
393 /* But before we can set the absolute left-coordinate of the
394 * SVG, we need to know where it is now. Note: without the
395 * "px" this doesn't default to pixels like CSS does. */
396 const svg = document.querySelector("svg");
397 svg.style.left = (svg.getBoundingClientRect().left + hdelta) + "px";
401 /******************************/
402 /* Set the service identifier */
403 /******************************/
404 function set_service_id() {
405 const sid = document.getElementById("serviceid");
407 /* Get the "serviceid" from the querystring if it's there */
408 const params = new URLSearchParams(document.location.search);
409 if (params.get("serviceid")) {
410 sid.textContent = params.get("serviceid");
413 /* Otherwise, leave it at "F" */
416 /******************************/
417 /* Set the service name */
418 /******************************/
419 function set_service_name() {
420 const sid = document.getElementById("servicename");
422 /* Get the "servicename" from the querystring if it's there */
423 const params = new URLSearchParams(document.location.search);
424 if (params.get("servicename")) {
425 sid.textContent = params.get("servicename");
428 /* Otherwise, leave it at "BaltimoreLink" */
431 /****************************************/
432 /* Set and reposition the security code */
433 /****************************************/
435 function set_code() {
436 const ct = document.getElementById("codetext");
438 /* Get the "code" from the querystring if it's there */
439 const params = new URLSearchParams(document.location.search);
440 if (params.get("code")) {
441 ct.textContent = params.get("code").toUpperCase();
444 /* Otherwise, use a random code */
445 const bucket = ["
0","
1","
2","
3","
4","
5","
6","
7","
8","
9",
446 "A","B","C","D","E","F","G","H","I","J",
447 "K","L","M","N","O","P","Q","R","S","T",
448 "U","V","W","X","Y","Z"];
450 /* Two random ints between
0 and
35 */
451 const i1 = Math.floor(Math.random() *
36);
452 const i2 = Math.floor(Math.random() *
36);
453 const d1 = bucket[i1];
454 const d2 = bucket[i2];
455 ct.textContent = d1 + d2;
460 function center_code() {
461 /* Center the security code inside its red box */
462 const ct = document.getElementById("codetext");
463 const bg = document.getElementById("codebg");
465 /* First, find the center of the red box */
466 const r1 = bg.getBoundingClientRect();
467 const c1 = r1.left + (r1.width /
2);
469 /* Now the center of the code text */
470 const r2 = ct.getBoundingClientRect();
471 const c2 = r2.left + (r2.width /
2);
473 /* What do we add to c2 to make it equal to c1? */
474 const hdelta = c1 - c2;
476 /* We've measured everything so far in "client rect"
477 * coordinates, because that's the only available measurement
478 * we have for the width of the
<text> element after futzing
479 * with its contents. But when we reposition that
<text>
480 * element, it will be by adjusting its "x" attribute, and
481 * that attribute uses a different coordinate system than the
482 * client rect does. Specifically, "x" refers to an offset
483 * within the SVG's coordinate system, and the client rect
484 * coordinates are pixels on-screen. To convert between the
485 * two, we can take the "width" attribute of the background
486 * element and compare it to the width of the background
487 * element's client rect. Since the size of the background is
488 * fixed, this should give us a multiplier that turns client recr
489 * distances (what we have) into SVG distances (what we want) */
490 const client_to_svg = parseFloat(bg.getAttribute("width"))/r1.width;
492 /* Convert hdelta from client rect to SVG coordinates */
493 const svg_hdelta = hdelta * client_to_svg;
495 /* Since this
<text> element has an "x" attribute it's easier for
496 * us to shift that than it is to mess with the "left" style. */
497 ct.setAttribute("x", parseFloat(ct.getAttribute("x")) + svg_hdelta);
500 /*****************************************/
501 /* Next, set up the ticket date and time */
502 /*****************************************/
504 function set_ticket_expiry() {
505 /* There are two parameters, time and date, that we store in one
506 * underlying "date" variable. Default both to an hour and a
507 * half from now. This is what the CharmPass app does for
508 * one-way tickets. */
509 const date = new Date();
511 /* BaltimoreLink and MARC Train are valid for an hour and a half */
513 const params = new URLSearchParams(document.location.search);
514 if (params.get("servicename") == "Commuter Bus") {
515 /* But commuter bus tickets are only valid for ten minutes */
519 /* We use the low-level get/setTime to change the number of
520 * milliseconds since the epoch that this date represents
521 * Obviously correct, and avoids all suspicious corner cases
522 * for a few more decades. */
523 date.setTime(date.getTime() + (minutes*
60*
1000));
525 tt = document.getElementById("tickettime");
526 tt.textContent = date.toLocaleTimeString();
528 const td = document.getElementById("ticketdate");
534 td.textContent = date.toLocaleDateString("en-US", dateopts);
538 /*********************************************************/
539 /* Finally, the onclick handler for the night/day switch */
540 /*********************************************************/
542 /* We always start in "day" mode */
546 sky.style.fill = "#efb02f";
549 function set_night() {
550 sky.style.fill = "#
143b66";
553 function swap_colors() {
565 /*******************************************************/
566 /* Compute the MARC "zone" from its origin/destination */
567 /*******************************************************/
569 /* Sorted on the first component, then the second */
583 /* Compute the zone (string) for the given origin/destination pair.
584 * If we don't know it or if you chose in invalid pair (destination
585 * not on the same line as your origin?) then the empty string is
587 function compute_marc_zone(src, dest) {
588 /* Forward direction key for zone_map */
589 const fwd = src + "_" + dest;
591 /* Reverse direction key for zone_map. The zone_map only
592 * has them listed in one direction, so we check both
593 * directions here. */
594 const rev = dest + "_" + src;
596 /* The default. Obviously wrong for when we don't
597 * have the necessary data. */
601 zone = zone_map[fwd];
603 else if (zone_map[rev]) {
604 zone = zone_map[rev];
607 /* Convert the number to a string */
622 function set_marc_zone() {
623 const params = new URLSearchParams(document.location.search);
624 if (params.get("origin") && params.get("destination")) {
625 const src = params.get("origin");
626 const dest = params.get("destination");
627 const zone = compute_marc_zone(src, dest);
629 /* TODO: actually set the zone */
634 /******************************************/
635 /* Display the ticket (and hide the menu) */
636 /******************************************/
639 /* To create our "window" onto the scene, we're going to slide the
640 * SVG off the left-hand side of the screen, and we don't want
641 * scroll bars to appear. */
642 document.body.style.overflow = "hidden";
643 document.body.style.margin = "
0";
644 document.body.style.padding = "
0";
646 const svg = document.querySelector("svg");
647 const menu = document.getElementById("menu");
648 svg.style.display = "initial";
649 menu.style.display = "none";
652 /*****************************************************/
653 /* Add event handlers for all of the functions above */
654 /*****************************************************/
656 const params = new URLSearchParams(document.location.search);
657 if (params.get("go")) {
658 /* First unhide the SVG (swap it with the form) */
659 window.addEventListener("load", go);
661 /* Center the ticket once when the page has loaded */
662 window.addEventListener("load", center_ticket);
664 /* Re-center the ticket when the window is resized */
665 window.addEventListener("resize", center_ticket);
667 /* Set the service identifier when the page has loaded */
668 window.addEventListener("load", set_service_id);
670 /* Set the service name when the page has loaded */
671 window.addEventListener("load", set_service_name);
673 /* Set the security code text when the page has loaded */
674 window.addEventListener("load", set_code);
676 /* Center the security code text when the page has loaded; in
677 * particular, after we set the code. */
678 window.addEventListener("load", center_code);
680 /* Set the ticket expiration date/time upon page load */
681 window.addEventListener("load", set_ticket_expiry);
683 /* Set the MARC Train zone, if applicable */
684 window.addEventListener("load", set_marc_zone);
686 /* Swap colors when the screen is tapped */
687 document.body.addEventListener("click", swap_colors);