]> gitweb.michael.orlitzky.com - charm-bypass.git/blob - index.html.in
index.html.in: change the slogan again
[charm-bypass.git] / index.html.in
1 <!doctype html>
2 <html lang="en-US">
3 <head>
4 <meta name="viewport" content="width=device-width, initial-scale=1" />
5 <link rel="icon" href="favicon.svg" />
6
7 <title>
8 CharmBypass: it's transit equity y'all
9 </title>
10
11 <style>
12 input[type=submit] {
13 margin-top: 1em;
14 margin-bottom: 1em;
15 }
16
17 svg {
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. */
23 position: fixed;
24 top: 0;
25 left: 0;
26 height: 100%;
27
28 /* Hide everything by default. We only show it once the user has
29 * submitted the menu form */
30 display: none;
31 }
32
33 /* The blinking fade in/out animation for the ticket date and time */
34 @keyframes blink {
35 25% {
36 opacity: 0.5;
37 }
38 50% {
39 opacity: 0;
40 }
41 75% {
42 opacity: 0.5;
43 }
44 }
45
46 #tickettime, #ticketdate {
47 /* 300 two-second blinks is ten minutes */
48 animation: blink 2s linear 300;
49 }
50
51 /* Define, load, and specify the custom font we use for the ticket
52 * date, time, and service name. */
53 @font-face {
54 font-family: "CharmBypass Regular";
55 src:
56 url("data:font/woff2;base64,@CBPREGULAR@") format("woff2")
57 }
58
59 #origindest, #servicename, #tickettime, #ticketdate, #codetext, #zone {
60 font-family: "CharmBypass Regular", sans-serif;
61 }
62
63 @font-face {
64 font-family: "CharmBypass Bold";
65 src:
66 url("data:font/woff2;base64,@CBPBOLD@") format("woff2")
67 }
68
69 #serviceid {
70 font-family: "CharmBypass Bold", sans-serif;
71 }
72
73 /************************/
74 /* Scrolling animations */
75 /************************/
76
77 /* Bus */
78 @keyframes busroll {
79 from {
80 transform: translateX(0%);
81 }
82 to {
83 transform: translateX(-100%);
84 }
85 }
86
87 #bus {
88 animation: busroll 23s linear infinite;
89 }
90
91
92 /* Tram */
93 @keyframes tramroll {
94 from {
95 transform: translateX(0%);
96 }
97 to {
98 transform: translateX(100%);
99 }
100 }
101
102 #tram {
103 animation: tramroll 17s linear infinite;
104 }
105
106
107 /* Tram */
108 @keyframes trainroll {
109 from {
110 transform: translateX(0%);
111 }
112 to {
113 transform: translateX(100%);
114 }
115 }
116
117 #train {
118 animation: trainroll 11s linear infinite;
119 }
120
121
122 /* Clouds */
123 @keyframes cloudsfloat {
124 from {
125 transform: translateX(0%);
126 }
127 to {
128 transform: translateX(-50%);
129 }
130 }
131
132 #clouds {
133 animation: cloudsfloat 40s linear infinite;
134 }
135
136 @keyframes cloudscopyfloat {
137 from {
138 transform: translateX(0%);
139 }
140 to {
141 transform: translateX(-50%);
142 }
143 }
144
145 #cloudscopy {
146 animation: cloudscopyfloat 40s linear infinite;
147 }
148
149
150 /* Trees */
151 @keyframes treespass {
152 from {
153 transform: translateX(0%);
154 }
155 to {
156 transform: translateX(-50%);
157 }
158 }
159
160 #trees {
161 /* The trees move a little faster than the clouds */
162 animation: treespass 30s linear infinite;
163 }
164
165 @keyframes treescopypass {
166 from {
167 transform: translateX(0%);
168 }
169 to {
170 transform: translateX(-50%);
171 }
172 }
173
174 #treescopy {
175 /* The trees move a little faster than the clouds */
176 animation: treescopypass 30s linear infinite;
177 }
178
179
180 /* City skyline */
181 @keyframes cityscroll {
182 from {
183 transform: translateX(0%);
184 }
185 to {
186 transform: translateX(-50%);
187 }
188 }
189
190 #city {
191 /* The city moves faster than the clouds but slower
192 * than the trees */
193 animation: cityscroll 35s linear infinite;
194 }
195
196 @keyframes citycopyscroll {
197 from {
198 transform: translateX(0%);
199 }
200 to {
201 transform: translateX(-50%);
202 }
203 }
204
205 #citycopy {
206 /* The city moves faster than the clouds but slower
207 * than the trees */
208 animation: citycopyscroll 35s linear infinite;
209 }
210 </style>
211 </head>
212
213 <body>
214 <div id="menu">
215 <h1>CharmBypass</h1>
216 <h2>it's transit equity y'all</h2>
217
218 <p>
219 <em>Hint:</em> If you think the driver or fare inspector will
220 actually check it, the daily security code is the same on a
221 $2.00 BaltimoreLink ticket as it is on a $9.00 MARC Train
222 ticket. It's also the same on your friend's phone, or for
223 anyone else in Maryland that day.
224 </p>
225
226 <form>
227 <fieldset>
228 <legend>BaltimoreLink (Bus, Light Rail, Metro)</legend>
229 <div>
230 <label for="code1">
231 Daily security code (optional):
232 </label>
233 <input id="code1"
234 name="code"
235 type="text"
236 minlength="2"
237 maxlength="2"
238 pattern="[a-zA-Z0-9]*" />
239 </div>
240 <input type="hidden" name="servicename" value="BaltimoreLink" />
241 <input type="submit" name="go" value="Get Ticket" />
242 </fieldset>
243 </form>
244 <form>
245 <fieldset>
246 <legend>Commuter Bus</legend>
247 <input type="hidden" name="serviceid" value="R" />
248 <input type="hidden" name="servicename" value="Commuter Bus" />
249
250 <div>
251 <label for="code2">
252 Daily security code (optional):
253 </label>
254 <input id="code2"
255 name="code"
256 type="text"
257 minlength="2"
258 maxlength="2"
259 pattern="[a-zA-Z0-9]*" />
260 </div>
261
262 <h3>Zone</h3>
263 <div>
264 <input required type="radio" id="zone1" name="zone" value="Zone 1" />
265 <label for="zone1">Zone 1</label>
266 </div>
267 <div>
268 <input required type="radio" id="zone2" name="zone" value="Zone 2" />
269 <label for="zone2">Zone 2</label>
270 </div>
271 <div>
272 <input required type="radio" id="zone3" name="zone" value="Zone 3" />
273 <label for="zone3">Zone 3</label>
274 </div>
275 <div>
276 <input required type="radio" id="zone4" name="zone" value="Zone 4" />
277 <label for="zone4">Zone 4</label>
278 </div>
279 <div>
280 <input required type="radio" id="zone5" name="zone" value="Zone 5" />
281 <label for="zone5">Zone 5</label>
282 </div>
283
284 <input type="submit" name="go" value="Get Ticket" />
285 </fieldset>
286 </form>
287 <form>
288 <fieldset>
289 <legend>MARC Train</legend>
290
291 <div>
292 <label for="code3">
293 Daily security code (optional):
294 </label>
295 <input id="code3"
296 name="code"
297 type="text"
298 minlength="2"
299 maxlength="2"
300 pattern="[a-zA-Z0-9]*" />
301 </div>
302
303 <h3>Origin</h3>
304
305 <div>
306 <input required type="radio" id="origin1" name="origin" value="BAL" />
307 <label for="origin1">Baltimore/Penn (Penn Line)</label>
308 </div>
309 <div>
310 <input required type="radio" id="origin2" name="origin" value="BCA" />
311 <label for="origin2">Baltimore/Camden (Camden Line)</label>
312 </div>
313 <div>
314 <input required type="radio" id="origin3" name="origin" value="BWE" />
315 <label for="origin3">Bowie State (Penn Line)</label>
316 </div>
317 <div>
318 <input required type="radio" id="origin4" name="origin" value="BWI" />
319 <label for="origin4">BWI Airport (Penn Line)</label>
320 </div>
321 <div>
322 <input required type="radio" id="origin5" name="origin" value="CPK" />
323 <label for="origin5">College Park (Camden Line)</label>
324 </div>
325 <div>
326 <input required type="radio" id="origin6" name="origin" value="SEB" />
327 <label for="origin6">Seabrook (Penn Line)</label>
328 </div>
329 <div>
330 <input required type="radio" id="origin7" name="origin" value="WAS" />
331 <label for="origin7">Washington D.C.</label>
332 </div>
333 <div>
334 <input required type="radio" id="origin8" name="origin" value="WBL" />
335 <label for="origin8">West Baltimore (Penn Line)</label>
336 </div>
337
338 <h3>Destination</h3>
339 <div>
340 <input required type="radio" id="destination1" name="destination" value="BAL" />
341 <label for="destination1">Baltimore/Penn (Penn Line)</label>
342 </div>
343 <div>
344 <input required type="radio" id="destination2" name="destination" value="BCA" />
345 <label for="destination2">Baltimore/Camden (Camden Line)</label>
346 </div>
347 <div>
348 <input required type="radio" id="destination3" name="destination" value="BWE" />
349 <label for="destination3">Bowie State (Penn Line)</label>
350 </div>
351 <div>
352 <input required type="radio" id="destination4" name="destination" value="BWI" />
353 <label for="destination4">BWI Airport (Penn Line)</label>
354 </div>
355 <div>
356 <input required type="radio" id="destination5" name="destination" value="CPK" />
357 <label for="destination5">College Park (Camden Line)</label>
358 </div>
359 <div>
360 <input required type="radio" id="destination6" name="destination" value="SEB" />
361 <label for="destination6">Seabrook (Penn Line)</label>
362 </div>
363 <div>
364 <input required type="radio" id="destination7" name="destination" value="WAS" />
365 <label for="destination7">Washington D.C.</label>
366 </div>
367 <div>
368 <input required type="radio" id="destination8" name="destination" value="WBL" />
369 <label for="destination8">West Baltimore (Penn Line)</label>
370 </div>
371
372 <input type="hidden" name="serviceid" value="R" />
373 <input type="hidden" name="servicename" value="MARC Train" />
374 <input type="submit" name="go" value="Get Ticket" />
375 </fieldset>
376 </form>
377 </div>
378
379 @SVGDATA@
380
381 <script>
382
383 /***********************************************/
384 /* First, center the ticket within the browser */
385 /***********************************************/
386
387 function center_ticket() {
388 /* We're relying on the SVG being the full height of the
389 * viewport already, and on the aspect ratio being
390 * preserved. First, find the center of the ticket. */
391 const r = document.getElementById("ticket").getBoundingClientRect();
392 const c = r.left + (r.width / 2);
393
394 /* That's the center-line of the ticket. We want to move it to
395 * the center-line of the viewport. */
396 const vc = document.documentElement.clientWidth / 2;
397
398 /* This is how much we need to translate the SVG */
399 const hdelta = vc - c;
400
401 /* But before we can set the absolute left-coordinate of the
402 * SVG, we need to know where it is now. Note: without the
403 * "px" this doesn't default to pixels like CSS does. */
404 const svg = document.querySelector("svg");
405 svg.style.left = (svg.getBoundingClientRect().left + hdelta) + "px";
406 }
407
408
409 /******************************/
410 /* Set the service identifier */
411 /******************************/
412 function set_service_id() {
413 const sid = document.getElementById("serviceid");
414
415 /* Get the "serviceid" from the querystring if it's there */
416 const params = new URLSearchParams(document.location.search);
417 if (params.get("serviceid")) {
418 sid.textContent = params.get("serviceid");
419 }
420
421 /* Otherwise, leave it at "F" */
422 }
423
424 /************************/
425 /* Set the service name */
426 /************************/
427 function set_service_name() {
428 const sid = document.getElementById("servicename");
429
430 /* Get the "servicename" from the querystring if it's there */
431 const params = new URLSearchParams(document.location.search);
432 if (params.get("servicename")) {
433 sid.textContent = params.get("servicename");
434 }
435
436 /* Otherwise, leave it at "BaltimoreLink" */
437 }
438
439
440 /************************/
441 /* Set the service zone */
442 /************************/
443 function set_service_zone(event, zone) {
444 /* We can take the zone as a parameter too; this allows us to
445 * use this function for the (computed) MARC Train zone and
446 * not just the querystring Commuter Bus zone. The extra
447 * "event" parameter is there for the event listener, which
448 * would otherwise stuff an onload event into the zone
449 * parameter. "Thankfully" javascript lets us call a
450 * two-argument function with one argument and thereby abuse
451 * the event handler for this. */
452 const z = document.getElementById("zone");
453 const params = new URLSearchParams(document.location.search);
454
455 if (zone) {
456 z.textContent = zone;
457 z.style.display = "block"; /* It's hidden by default */
458 }
459 else if (params.get("zone")) {
460 /* Get the "zone" from the querystring if it's there */
461 z.textContent = params.get("zone");
462 z.style.display = "block"; /* It's hidden by default */
463 }
464
465 /* Otherwise, leave it blank (and hidden) */
466 }
467
468 /***********************************************************/
469 /* Resize the ticket background based on the service name */
470 /***********************************************************/
471
472 function resize_ticket() {
473 /* Get the "servicename" from the querystring if it's there */
474 const params = new URLSearchParams(document.location.search);
475 const tbg = document.getElementById("ticketbg");
476 const t = document.getElementById("ticket");
477 const sn = document.getElementById("servicename");
478
479 if (params.get("servicename") == "Commuter Bus") {
480 /* The top of the background is initially at y=246.859, and
481 * we scale it by a factor of 1.12 to y=276.482 for a change
482 * of 29.623. So after we scale it, we translate it upwards
483 * by that amount to put it back where it started. */
484 tbg.setAttribute("transform", "translate(0 -29.623) scale(1 1.12)");
485
486 /* Now translate the entire ticket up by the magic amount, 1/5
487 * of the size change we made to the background. This ratio
488 * was found by measuring pixels in side-by-side screenshots
489 * of BaltimoreLink and Commuter Bus tickets. */
490 t.setAttribute("transform", "translate(0 -9.33)");
491
492 /* More magic numbers discovered by comparing the two
493 * tickets overlayed in inkscape */
494 sn.setAttribute("transform", "translate(0 64.28)");
495 }
496 else if (params.get("servicename") == "MARC Train") {
497 /* insane tricks are explained above */
498 tbg.setAttribute("transform",
499 "translate(0 -72.378) scale(1 1.2932)");
500 t.setAttribute("transform", "translate(0 -67.17)");
501 sn.setAttribute("transform", "translate(0 131.0)");
502 }
503
504 /* Otherwise, leave it alone. The SVG was designed with the
505 * BaltimoreLink ticket in mind */
506 }
507
508 /****************************************/
509 /* Set and reposition the security code */
510 /****************************************/
511
512 function set_code() {
513 const ct = document.getElementById("codetext");
514
515 /* Get the "code" from the querystring if it's there */
516 const params = new URLSearchParams(document.location.search);
517 if (params.get("code")) {
518 ct.textContent = params.get("code").toUpperCase();
519 }
520 else {
521 /* Otherwise, use a random code */
522 const bucket = ["0","1","2","3","4","5","6","7","8","9",
523 "A","B","C","D","E","F","G","H","I","J",
524 "K","L","M","N","O","P","Q","R","S","T",
525 "U","V","W","X","Y","Z"];
526
527 /* Two random ints between 0 and 35 */
528 const i1 = Math.floor(Math.random() * 36);
529 const i2 = Math.floor(Math.random() * 36);
530 const d1 = bucket[i1];
531 const d2 = bucket[i2];
532 ct.textContent = d1 + d2;
533 }
534 }
535
536
537 function center_code() {
538 /* Center the security code inside its red box */
539 const ct = document.getElementById("codetext");
540 const bg = document.getElementById("codebg");
541
542 /* First, find the center of the red box */
543 const r1 = bg.getBoundingClientRect();
544 const c1 = r1.left + (r1.width / 2);
545
546 /* Now the center of the code text */
547 const r2 = ct.getBoundingClientRect();
548 const c2 = r2.left + (r2.width / 2);
549
550 /* What do we add to c2 to make it equal to c1? */
551 const hdelta = c1 - c2;
552
553 /* We've measured everything so far in "client rect"
554 * coordinates, because that's the only available measurement
555 * we have for the width of the <text> element after futzing
556 * with its contents. But when we reposition that <text>
557 * element, it will be by adjusting its "x" attribute, and
558 * that attribute uses a different coordinate system than the
559 * client rect does. Specifically, "x" refers to an offset
560 * within the SVG's coordinate system, and the client rect
561 * coordinates are pixels on-screen. To convert between the
562 * two, we can take the "width" attribute of the background
563 * element and compare it to the width of the background
564 * element's client rect. Since the size of the background is
565 * fixed, this should give us a multiplier that turns client recr
566 * distances (what we have) into SVG distances (what we want) */
567 const client_to_svg = parseFloat(bg.getAttribute("width"))/r1.width;
568
569 /* Convert hdelta from client rect to SVG coordinates */
570 const svg_hdelta = hdelta * client_to_svg;
571
572 /* Since this <text> element has an "x" attribute it's easier for
573 * us to shift that than it is to mess with the "left" style. */
574 ct.setAttribute("x", parseFloat(ct.getAttribute("x")) + svg_hdelta);
575 }
576
577 /*****************************************/
578 /* Next, set up the ticket date and time */
579 /*****************************************/
580
581 function set_ticket_expiry() {
582 /* There are two parameters, time and date, that we store in one
583 * underlying "date" variable. Default both to an hour and a
584 * half from now. This is what the CharmPass app does for
585 * one-way tickets. */
586 const date = new Date();
587
588 /* BaltimoreLink and MARC Train are valid for an hour and a half */
589 let minutes = 90;
590 const params = new URLSearchParams(document.location.search);
591 if (params.get("servicename") == "Commuter Bus") {
592 /* But commuter bus tickets are only valid for ten minutes */
593 minutes = 10;
594 }
595
596 /* We use the low-level get/setTime to change the number of
597 * milliseconds since the epoch that this date represents
598 * Obviously correct, and avoids all suspicious corner cases
599 * for a few more decades. */
600 date.setTime(date.getTime() + (minutes*60*1000));
601
602 tt = document.getElementById("tickettime");
603 tt.textContent = date.toLocaleTimeString();
604
605 const td = document.getElementById("ticketdate");
606 const dateopts = {
607 day: "2-digit",
608 month: "2-digit",
609 year: "2-digit"
610 };
611 td.textContent = date.toLocaleDateString("en-US", dateopts);
612 }
613
614
615 /*********************************************************/
616 /* Finally, the onclick handler for the night/day switch */
617 /*********************************************************/
618
619 /* We always start in "day" mode */
620 is_day = true;
621
622 function set_day() {
623 sky.style.fill = "#efb02f";
624 }
625
626 function set_night() {
627 sky.style.fill = "#143b66";
628 }
629
630 function swap_colors() {
631 if (is_day) {
632 set_night();
633 is_day = false;
634 }
635 else {
636 set_day();
637 is_day = true;
638 }
639 }
640
641
642 /*******************************************************/
643 /* Compute the MARC "zone" from its origin/destination */
644 /*******************************************************/
645
646 /* Sorted on the first component, then the second */
647 const zone_map = {
648 BAL_BWE: 2,
649 BAL_BWI: 1,
650 BAL_SEB: 3,
651 BAL_WAS: 4,
652 BAL_WBL: 1,
653 BCA_CPK_: 3,
654 BCA_WAS_: 4,
655 BWI_BWE: 1,
656 BWI_WAS: 3,
657 BWI_WBL: 1
658 };
659
660 /* Compute the zone (string) for the given origin/destination pair.
661 * If we don't know it or if you chose in invalid pair (destination
662 * not on the same line as your origin?) then the empty string is
663 * returned. */
664 function compute_marc_zone(src, dest) {
665 /* Forward direction key for zone_map */
666 const fwd = src + "_" + dest;
667
668 /* Reverse direction key for zone_map. The zone_map only
669 * has them listed in one direction, so we check both
670 * directions here. */
671 const rev = dest + "_" + src;
672
673 /* The default. Obviously wrong for when we don't
674 * have the necessary data. */
675 let zone = -1;
676
677 if (zone_map[fwd]) {
678 zone = zone_map[fwd];
679 }
680 else if (zone_map[rev]) {
681 zone = zone_map[rev];
682 }
683
684 /* Convert the number to a string */
685 switch (zone) {
686 case 1:
687 return "One Zone";
688 case 2:
689 return "Two Zone";
690 case 3:
691 return "Three Zone";
692 case 4:
693 return "Four Zone";
694 default:
695 return "";
696 }
697 }
698
699 function set_marc_zone() {
700 const params = new URLSearchParams(document.location.search);
701 if (params.get("origin") && params.get("destination")) {
702 const src = params.get("origin");
703 const dest = params.get("destination");
704 const zone = compute_marc_zone(src, dest);
705
706 set_service_zone(null, zone);
707 }
708 }
709
710
711 /*****************************************************/
712 /* Set the origin and destination for the MARC Train */
713 /*****************************************************/
714
715 function set_marc_origin_destination() {
716 const params = new URLSearchParams(document.location.search);
717 if (!params.get("origin") || !params.get("destination")) {
718 return;
719 }
720
721 const src = params.get("origin");
722 const dest = params.get("destination");
723
724 /* origindest contains both the origin and destination */
725 const origindest = document.getElementById("origindest");
726
727 const origin = document.getElementById("origin");
728 const destination = document.getElementById("destination");
729
730 origin.textContent = params.get("origin");
731 destination.textContent = params.get("destination");
732
733 origindest.style.display = "block"; /* It's hidden by default */
734 }
735
736 /******************************************/
737 /* Display the ticket (and hide the menu) */
738 /******************************************/
739
740 function go() {
741 /* To create our "window" onto the scene, we're going to slide the
742 * SVG off the left-hand side of the screen, and we don't want
743 * scroll bars to appear. */
744 document.body.style.overflow = "hidden";
745 document.body.style.margin = "0";
746 document.body.style.padding = "0";
747
748 const svg = document.querySelector("svg");
749 const menu = document.getElementById("menu");
750 svg.style.display = "initial";
751 menu.style.display = "none";
752 }
753
754 /*****************************************************/
755 /* Add event handlers for all of the functions above */
756 /*****************************************************/
757
758 const params = new URLSearchParams(document.location.search);
759 if (params.get("go")) {
760 /* First unhide the SVG (swap it with the form) */
761 window.addEventListener("load", go);
762
763 /* Center the ticket once when the page has loaded */
764 window.addEventListener("load", center_ticket);
765
766 /* Re-center the ticket when the window is resized */
767 window.addEventListener("resize", center_ticket);
768
769 /* Set the service identifier when the page has loaded */
770 window.addEventListener("load", set_service_id);
771
772 /* Set the service name when the page has loaded */
773 window.addEventListener("load", set_service_name);
774
775 /* Set the service zone when the page has loaded */
776 window.addEventListener("load", set_service_zone);
777
778 /* Resize the ticket background if necessary */
779 window.addEventListener("load", resize_ticket);
780
781 /* Set the security code text when the page has loaded */
782 window.addEventListener("load", set_code);
783
784 /* Center the security code text when the page has loaded; in
785 * particular, after we set the code. */
786 window.addEventListener("load", center_code);
787
788 /* Set the ticket expiration date/time upon page load */
789 window.addEventListener("load", set_ticket_expiry);
790
791 /* Set the MARC Train origin and destination, if applicable */
792 window.addEventListener("load", set_marc_origin_destination);
793
794 /* Set the MARC Train zone, if applicable */
795 window.addEventListener("load", set_marc_zone);
796
797 /* Swap colors when the screen is tapped */
798 document.body.addEventListener("click", swap_colors);
799 }
800
801 </script>
802 </body>
803 </html>