4 <meta name=
"viewport" content=
"width=device-width, initial-scale=1" />
7 CharmBypass: transit equity whether you like it or not
17 /* Set the height to
100% of the screen, which we'll keep; and the
18 * initial position to (
0,
0), which we're going to change
19 * every time the window is resized, because the exact amount
20 * that we have to slide the SVG to the left to get the ticket
21 * into the center will change. */
27 /* Hide everything by default. We only show it once the user has
28 * submitted the menu form */
32 /* The blinking fade in/out animation for the ticket date and time */
45 #tickettime, #ticketdate {
46 /*
300 two-second blinks is ten minutes */
47 animation: blink
2s linear
300;
50 /* Define, load, and specify the custom font we use for the ticket
51 * date, time, and service name. */
53 font-family: "CharmBypass Regular";
55 url("data:font/woff2;base64,@CBPREGULAR@") format("woff2")
58 #servicename, #tickettime, #ticketdate, #codetext {
59 font-family: "CharmBypass Regular", sans-serif;
63 font-family: "CharmBypass Bold";
65 url("data:font/woff2;base64,@CBPBOLD@") format("woff2")
69 font-family: "CharmBypass Bold", sans-serif;
73 /************************/
74 /* Scrolling animations */
75 /************************/
80 transform: translateX(
0%);
83 transform: translateX(-
100%);
88 animation: busroll
23s linear infinite;
95 transform: translateX(
0%);
98 transform: translateX(
100%);
103 animation: tramroll
17s linear infinite;
108 @keyframes trainroll {
110 transform: translateX(
0%);
113 transform: translateX(
100%);
118 animation: trainroll
11s linear infinite;
123 @keyframes cloudsfloat {
125 transform: translateX(
0%);
128 transform: translateX(-
50%);
133 animation: cloudsfloat
40s linear infinite;
136 @keyframes cloudscopyfloat {
138 transform: translateX(
0%);
141 transform: translateX(-
50%);
146 animation: cloudscopyfloat
40s linear infinite;
151 @keyframes treespass {
153 transform: translateX(
0%);
156 transform: translateX(-
50%);
161 /* The trees move a little faster than the clouds */
162 animation: treespass
30s linear infinite;
165 @keyframes treescopypass {
167 transform: translateX(
0%);
170 transform: translateX(-
50%);
175 /* The trees move a little faster than the clouds */
176 animation: treescopypass
30s linear infinite;
181 @keyframes cityscroll {
183 transform: translateX(
0%);
186 transform: translateX(-
50%);
191 /* The city moves faster than the clouds but slower
193 animation: cityscroll
35s linear infinite;
196 @keyframes citycopyscroll {
198 transform: translateX(
0%);
201 transform: translateX(-
50%);
206 /* The city moves faster than the clouds but slower
208 animation: citycopyscroll
35s linear infinite;
216 <h2>transit equity whether you like it or not
</h2>
219 <legend>BaltimoreLink (Bus, Light Rail, Metro)
</legend>
220 <input type=
"hidden" name=
"servicename" value=
"BaltimoreLink" />
221 <input type=
"submit" name=
"go" value=
"Get Ticket" />
226 <legend>Commuter Bus
</legend>
227 <input type=
"hidden" name=
"serviceid" value=
"R" />
228 <input type=
"hidden" name=
"servicename" value=
"Commuter Bus" />
232 <input type=
"radio" id=
"zone1" name=
"zone" value=
"Zone 1" />
233 <label for=
"zone1">Zone
1</label>
236 <input type=
"radio" id=
"zone2" name=
"zone" value=
"Zone 2" />
237 <label for=
"zone2">Zone
2</label>
240 <input type=
"radio" id=
"zone3" name=
"zone" value=
"Zone 3" />
241 <label for=
"zone3">Zone
3</label>
244 <input type=
"radio" id=
"zone4" name=
"zone" value=
"Zone 4" />
245 <label for=
"zone4">Zone
4</label>
248 <input type=
"radio" id=
"zone5" name=
"zone" value=
"Zone 5" />
249 <label for=
"zone5">Zone
5</label>
252 <input type=
"submit" name=
"go" value=
"Get Ticket" />
257 <legend>MARC Train
</legend>
262 <input type=
"radio" id=
"origin1" name=
"origin" value=
"BAL" />
263 <label for=
"origin1">Baltimore/Penn (Penn Line)
</label>
266 <input type=
"radio" id=
"origin2" name=
"origin" value=
"BCA" />
267 <label for=
"origin2">Baltimore/Camden (Camden Line)
</label>
270 <input type=
"radio" id=
"origin3" name=
"origin" value=
"BWE" />
271 <label for=
"origin3">Bowie State (Penn Line)
</label>
274 <input type=
"radio" id=
"origin4" name=
"origin" value=
"BWI" />
275 <label for=
"origin4">BWI Airport (Penn Line)
</label>
278 <input type=
"radio" id=
"origin5" name=
"origin" value=
"CPK" />
279 <label for=
"origin5">College Park (Camden Line)
</label>
282 <input type=
"radio" id=
"origin6" name=
"origin" value=
"SEB" />
283 <label for=
"origin6">Seabrook (Penn Line)
</label>
286 <input type=
"radio" id=
"origin7" name=
"origin" value=
"WAS" />
287 <label for=
"origin7">Washington D.C.
</label>
290 <input type=
"radio" id=
"origin8" name=
"origin" value=
"WBL" />
291 <label for=
"origin8">West Baltimore (Penn Line)
</label>
296 <input type=
"radio" id=
"destination1" name=
"destination" value=
"BAL" />
297 <label for=
"destination1">Baltimore/Penn (Penn Line)
</label>
300 <input type=
"radio" id=
"destination2" name=
"destination" value=
"BCA" />
301 <label for=
"destination2">Baltimore/Camden (Camden Line)
</label>
304 <input type=
"radio" id=
"destination3" name=
"destination" value=
"BWE" />
305 <label for=
"destination3">Bowie State (Penn Line)
</label>
308 <input type=
"radio" id=
"destination4" name=
"destination" value=
"BWI" />
309 <label for=
"destination4">BWI Airport (Penn Line)
</label>
312 <input type=
"radio" id=
"destination5" name=
"destination" value=
"CPK" />
313 <label for=
"destination5">College Park (Camden Line)
</label>
316 <input type=
"radio" id=
"destination6" name=
"destination" value=
"SEB" />
317 <label for=
"destination6">Seabrook (Penn Line)
</label>
320 <input type=
"radio" id=
"destination7" name=
"destination" value=
"WAS" />
321 <label for=
"destination7">Washington D.C.
</label>
324 <input type=
"radio" id=
"destination8" name=
"destination" value=
"WBL" />
325 <label for=
"destination8">West Baltimore (Penn Line)
</label>
328 <input type=
"hidden" name=
"serviceid" value=
"R" />
329 <input type=
"hidden" name=
"servicename" value=
"MARC Train" />
330 <input type=
"submit" name=
"go" value=
"Get Ticket" />
339 /***********************************************/
340 /* First, center the ticket within the browser */
341 /***********************************************/
343 function center_ticket() {
344 /* We're relying on the SVG being the full height of the
345 * viewport already, and on the aspect ratio being
346 * preserved. First, find the center of the ticket. */
347 const r = document.getElementById("ticket").getBoundingClientRect();
348 const c = r.left + (r.width /
2);
350 /* That's the center-line of the ticket. We want to move it to
351 * the center-line of the viewport. */
352 const vc = document.documentElement.clientWidth /
2;
354 /* This is how much we need to translate the SVG */
355 const hdelta = vc - c;
357 /* But before we can set the absolute left-coordinate of the
358 * SVG, we need to know where it is now. Note: without the
359 * "px" this doesn't default to pixels like CSS does. */
360 const svg = document.querySelector("svg");
361 svg.style.left = (svg.getBoundingClientRect().left + hdelta) + "px";
365 /******************************/
366 /* Set the service identifier */
367 /******************************/
368 function set_service_id() {
369 const sid = document.getElementById("serviceid");
371 /* Get the "serviceid" from the querystring if it's there */
372 const params = new URLSearchParams(document.location.search);
373 if (params.get("serviceid")) {
374 sid.textContent = params.get("serviceid");
377 /* Otherwise, leave it at "F" */
380 /******************************/
381 /* Set the service name */
382 /******************************/
383 function set_service_name() {
384 const sid = document.getElementById("servicename");
386 /* Get the "servicename" from the querystring if it's there */
387 const params = new URLSearchParams(document.location.search);
388 if (params.get("servicename")) {
389 sid.textContent = params.get("servicename");
392 /* Otherwise, leave it at "BaltimoreLink" */
395 /****************************************/
396 /* Set and reposition the security code */
397 /****************************************/
399 function set_code() {
400 const ct = document.getElementById("codetext");
402 /* Get the "code" from the querystring if it's there */
403 const params = new URLSearchParams(document.location.search);
404 if (params.get("code")) {
405 ct.textContent = params.get("code");
408 /* Otherwise, use a random code */
409 const bucket = ["
0","
1","
2","
3","
4","
5","
6","
7","
8","
9",
410 "A","B","C","D","E","F","G","H","I","J",
411 "K","L","M","N","O","P","Q","R","S","T",
412 "U","V","W","X","Y","Z"];
414 /* Two random ints between
0 and
35 */
415 const i1 = Math.floor(Math.random() *
36);
416 const i2 = Math.floor(Math.random() *
36);
417 const d1 = bucket[i1];
418 const d2 = bucket[i2];
419 ct.textContent = d1 + d2;
424 function center_code() {
425 /* Center the security code inside its red box */
426 const ct = document.getElementById("codetext");
427 const bg = document.getElementById("codebg");
429 /* First, find the center of the red box */
430 const r1 = bg.getBoundingClientRect();
431 const c1 = r1.left + (r1.width /
2);
433 /* Now the center of the code text */
434 const r2 = ct.getBoundingClientRect();
435 const c2 = r2.left + (r2.width /
2);
437 /* What do we add to c2 to make it equal to c1? */
438 const hdelta = c1 - c2;
440 /* We've measured everything so far in "client rect"
441 * coordinates, because that's the only available measurement
442 * we have for the width of the
<text> element after futzing
443 * with its contents. But when we reposition that
<text>
444 * element, it will be by adjusting its "x" attribute, and
445 * that attribute uses a different coordinate system than the
446 * client rect does. Specifically, "x" refers to an offset
447 * within the SVG's coordinate system, and the client rect
448 * coordinates are pixels on-screen. To convert between the
449 * two, we can take the "width" attribute of the background
450 * element and compare it to the width of the background
451 * element's client rect. Since the size of the background is
452 * fixed, this should give us a multiplier that turns client recr
453 * distances (what we have) into SVG distances (what we want) */
454 const client_to_svg = parseFloat(bg.getAttribute("width"))/r1.width;
456 /* Convert hdelta from client rect to SVG coordinates */
457 const svg_hdelta = hdelta * client_to_svg;
459 /* Since this
<text> element has an "x" attribute it's easier for
460 * us to shift that than it is to mess with the "left" style. */
461 ct.setAttribute("x", parseFloat(ct.getAttribute("x")) + svg_hdelta);
464 /*****************************************/
465 /* Next, set up the ticket date and time */
466 /*****************************************/
468 function set_ticket_expiry() {
469 /* There are two parameters, time and date, that we store in one
470 * underlying "date" variable. Default both to an hour and a
471 * half from now. This is what the CharmPass app does for
472 * one-way tickets. */
473 const date = new Date();
475 /* BaltimoreLink and MARC Train are valid for an hour and a half */
477 const params = new URLSearchParams(document.location.search);
478 if (params.get("servicename") == "Commuter Bus") {
479 /* But commuter bus tickets are only valid for ten minutes */
483 /* We use the low-level get/setTime to change the number of
484 * milliseconds since the epoch that this date represents
485 * Obviously correct, and avoids all suspicious corner cases
486 * for a few more decades. */
487 date.setTime(date.getTime() + (minutes*
60*
1000));
489 tt = document.getElementById("tickettime");
490 tt.textContent = date.toLocaleTimeString();
492 const td = document.getElementById("ticketdate");
498 td.textContent = date.toLocaleDateString("en-US", dateopts);
502 /*********************************************************/
503 /* Finally, the onclick handler for the night/day switch */
504 /*********************************************************/
506 /* We always start in "day" mode */
510 sky.style.fill = "#efb02f";
513 function set_night() {
514 sky.style.fill = "#
143b66";
517 function swap_colors() {
528 /******************************************/
529 /* Display the ticket (and hide the menu) */
530 /******************************************/
533 /* To create our "window" onto the scene, we're going to slide the
534 * SVG off the left-hand side of the screen, and we don't want
535 * scroll bars to appear. */
536 document.body.style.overflow = "hidden";
537 document.body.style.margin = "
0";
538 document.body.style.padding = "
0";
540 const svg = document.querySelector("svg");
541 const menu = document.getElementById("menu");
542 svg.style.display = "initial";
543 menu.style.display = "none";
546 /*****************************************************/
547 /* Add event handlers for all of the functions above */
548 /*****************************************************/
550 const params = new URLSearchParams(document.location.search);
551 if (params.get("go")) {
552 /* First unhide the SVG (swap it with the form) */
553 window.addEventListener("load", go);
555 /* Center the ticket once when the page has loaded */
556 window.addEventListener("load", center_ticket);
558 /* Re-center the ticket when the window is resized */
559 window.addEventListener("resize", center_ticket);
561 /* Set the service identifier when the page has loaded */
562 window.addEventListener("load", set_service_id);
564 /* Set the service name when the page has loaded */
565 window.addEventListener("load", set_service_name);
567 /* Set the security code text when the page has loaded */
568 window.addEventListener("load", set_code);
570 /* Center the security code text when the page has loaded; in
571 * particular, after we set the code. */
572 window.addEventListener("load", center_code);
574 /* Set the ticket expiration date/time upon page load */
575 window.addEventListener("load", set_ticket_expiry);
577 /* Swap colors when the screen is tapped */
578 document.body.addEventListener("click", swap_colors);