]> gitweb.michael.orlitzky.com - charm-bypass.git/blob - index.html.in
index.html.in: use "*" instead of "+" for input pattern validation
[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
6 <title>
7 CharmBypass: doing transit equity whether they like it or not
8 </title>
9
10 <style>
11 input[type=submit] {
12 margin-top: 1em;
13 margin-bottom: 1em;
14 }
15
16 svg {
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. */
22 position: fixed;
23 top: 0;
24 left: 0;
25 height: 100%;
26
27 /* Hide everything by default. We only show it once the user has
28 * submitted the menu form */
29 display: none;
30 }
31
32 /* The blinking fade in/out animation for the ticket date and time */
33 @keyframes blink {
34 25% {
35 opacity: 0.5;
36 }
37 50% {
38 opacity: 0;
39 }
40 75% {
41 opacity: 0.5;
42 }
43 }
44
45 #tickettime, #ticketdate {
46 /* 300 two-second blinks is ten minutes */
47 animation: blink 2s linear 300;
48 }
49
50 /* Define, load, and specify the custom font we use for the ticket
51 * date, time, and service name. */
52 @font-face {
53 font-family: "CharmBypass Regular";
54 src:
55 url("data:font/woff2;base64,@CBPREGULAR@") format("woff2")
56 }
57
58 #servicename, #tickettime, #ticketdate, #codetext {
59 font-family: "CharmBypass Regular", sans-serif;
60 }
61
62 @font-face {
63 font-family: "CharmBypass Bold";
64 src:
65 url("data:font/woff2;base64,@CBPBOLD@") format("woff2")
66 }
67
68 #serviceid {
69 font-family: "CharmBypass Bold", sans-serif;
70 font-weight: bold;
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>doing transit equity whether they like it or not</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 /* Set and reposition the security code */
441 /****************************************/
442
443 function set_code() {
444 const ct = document.getElementById("codetext");
445
446 /* Get the "code" from the querystring if it's there */
447 const params = new URLSearchParams(document.location.search);
448 if (params.get("code")) {
449 ct.textContent = params.get("code").toUpperCase();
450 }
451 else {
452 /* Otherwise, use a random code */
453 const bucket = ["0","1","2","3","4","5","6","7","8","9",
454 "A","B","C","D","E","F","G","H","I","J",
455 "K","L","M","N","O","P","Q","R","S","T",
456 "U","V","W","X","Y","Z"];
457
458 /* Two random ints between 0 and 35 */
459 const i1 = Math.floor(Math.random() * 36);
460 const i2 = Math.floor(Math.random() * 36);
461 const d1 = bucket[i1];
462 const d2 = bucket[i2];
463 ct.textContent = d1 + d2;
464 }
465 }
466
467
468 function center_code() {
469 /* Center the security code inside its red box */
470 const ct = document.getElementById("codetext");
471 const bg = document.getElementById("codebg");
472
473 /* First, find the center of the red box */
474 const r1 = bg.getBoundingClientRect();
475 const c1 = r1.left + (r1.width / 2);
476
477 /* Now the center of the code text */
478 const r2 = ct.getBoundingClientRect();
479 const c2 = r2.left + (r2.width / 2);
480
481 /* What do we add to c2 to make it equal to c1? */
482 const hdelta = c1 - c2;
483
484 /* We've measured everything so far in "client rect"
485 * coordinates, because that's the only available measurement
486 * we have for the width of the <text> element after futzing
487 * with its contents. But when we reposition that <text>
488 * element, it will be by adjusting its "x" attribute, and
489 * that attribute uses a different coordinate system than the
490 * client rect does. Specifically, "x" refers to an offset
491 * within the SVG's coordinate system, and the client rect
492 * coordinates are pixels on-screen. To convert between the
493 * two, we can take the "width" attribute of the background
494 * element and compare it to the width of the background
495 * element's client rect. Since the size of the background is
496 * fixed, this should give us a multiplier that turns client recr
497 * distances (what we have) into SVG distances (what we want) */
498 const client_to_svg = parseFloat(bg.getAttribute("width"))/r1.width;
499
500 /* Convert hdelta from client rect to SVG coordinates */
501 const svg_hdelta = hdelta * client_to_svg;
502
503 /* Since this <text> element has an "x" attribute it's easier for
504 * us to shift that than it is to mess with the "left" style. */
505 ct.setAttribute("x", parseFloat(ct.getAttribute("x")) + svg_hdelta);
506 }
507
508 /*****************************************/
509 /* Next, set up the ticket date and time */
510 /*****************************************/
511
512 function set_ticket_expiry() {
513 /* There are two parameters, time and date, that we store in one
514 * underlying "date" variable. Default both to an hour and a
515 * half from now. This is what the CharmPass app does for
516 * one-way tickets. */
517 const date = new Date();
518
519 /* BaltimoreLink and MARC Train are valid for an hour and a half */
520 let minutes = 90;
521 const params = new URLSearchParams(document.location.search);
522 if (params.get("servicename") == "Commuter Bus") {
523 /* But commuter bus tickets are only valid for ten minutes */
524 minutes = 10;
525 }
526
527 /* We use the low-level get/setTime to change the number of
528 * milliseconds since the epoch that this date represents
529 * Obviously correct, and avoids all suspicious corner cases
530 * for a few more decades. */
531 date.setTime(date.getTime() + (minutes*60*1000));
532
533 tt = document.getElementById("tickettime");
534 tt.textContent = date.toLocaleTimeString();
535
536 const td = document.getElementById("ticketdate");
537 const dateopts = {
538 day: "2-digit",
539 month: "2-digit",
540 year: "2-digit"
541 };
542 td.textContent = date.toLocaleDateString("en-US", dateopts);
543 }
544
545
546 /*********************************************************/
547 /* Finally, the onclick handler for the night/day switch */
548 /*********************************************************/
549
550 /* We always start in "day" mode */
551 is_day = true;
552
553 function set_day() {
554 sky.style.fill = "#efb02f";
555 }
556
557 function set_night() {
558 sky.style.fill = "#143b66";
559 }
560
561 function swap_colors() {
562 if (is_day) {
563 set_night();
564 is_day = false;
565 }
566 else {
567 set_day();
568 is_day = true;
569 }
570 }
571
572
573 /*******************************************************/
574 /* Compute the MARC "zone" from its origin/destination */
575 /*******************************************************/
576
577 /* Sorted on the first component, then the second */
578 const zone_map = {
579 BAL_BWE: 2,
580 BAL_BWI: 1,
581 BAL_SEB: 3,
582 BAL_WAS: 4,
583 BAL_WBL: 1,
584 BCA_CPK_: 3,
585 BCA_WAS_: 4,
586 BWI_BWE: 1,
587 BWI_WAS: 3,
588 BWI_WBL: 1
589 };
590
591 /* Compute the zone (string) for the given origin/destination pair.
592 * If we don't know it or if you chose in invalid pair (destination
593 * not on the same line as your origin?) then the empty string is
594 * returned. */
595 function compute_marc_zone(src, dest) {
596 /* Forward direction key for zone_map */
597 const fwd = src + "_" + dest;
598
599 /* Reverse direction key for zone_map. The zone_map only
600 * has them listed in one direction, so we check both
601 * directions here. */
602 const rev = dest + "_" + src;
603
604 /* The default. Obviously wrong for when we don't
605 * have the necessary data. */
606 let zone = -1;
607
608 if (zone_map[fwd]) {
609 zone = zone_map[fwd];
610 }
611 else if (zone_map[rev]) {
612 zone = zone_map[rev];
613 }
614
615 /* Convert the number to a string */
616 switch (zone) {
617 case 1:
618 return "One Zone";
619 case 2:
620 return "Two Zone";
621 case 3:
622 return "Three Zone";
623 case 4:
624 return "Four Zone";
625 default:
626 return "";
627 }
628 }
629
630 function set_marc_zone() {
631 const params = new URLSearchParams(document.location.search);
632 if (params.get("origin") && params.get("destination")) {
633 const src = params.get("origin");
634 const dest = params.get("destination");
635 const zone = compute_marc_zone(src, dest);
636
637 /* TODO: actually set the zone */
638 alert(zone);
639 }
640 }
641
642 /******************************************/
643 /* Display the ticket (and hide the menu) */
644 /******************************************/
645
646 function go() {
647 /* To create our "window" onto the scene, we're going to slide the
648 * SVG off the left-hand side of the screen, and we don't want
649 * scroll bars to appear. */
650 document.body.style.overflow = "hidden";
651 document.body.style.margin = "0";
652 document.body.style.padding = "0";
653
654 const svg = document.querySelector("svg");
655 const menu = document.getElementById("menu");
656 svg.style.display = "initial";
657 menu.style.display = "none";
658 }
659
660 /*****************************************************/
661 /* Add event handlers for all of the functions above */
662 /*****************************************************/
663
664 const params = new URLSearchParams(document.location.search);
665 if (params.get("go")) {
666 /* First unhide the SVG (swap it with the form) */
667 window.addEventListener("load", go);
668
669 /* Center the ticket once when the page has loaded */
670 window.addEventListener("load", center_ticket);
671
672 /* Re-center the ticket when the window is resized */
673 window.addEventListener("resize", center_ticket);
674
675 /* Set the service identifier when the page has loaded */
676 window.addEventListener("load", set_service_id);
677
678 /* Set the service name when the page has loaded */
679 window.addEventListener("load", set_service_name);
680
681 /* Set the security code text when the page has loaded */
682 window.addEventListener("load", set_code);
683
684 /* Center the security code text when the page has loaded; in
685 * particular, after we set the code. */
686 window.addEventListener("load", center_code);
687
688 /* Set the ticket expiration date/time upon page load */
689 window.addEventListener("load", set_ticket_expiry);
690
691 /* Set the MARC Train zone, if applicable */
692 window.addEventListener("load", set_marc_zone);
693
694 /* Swap colors when the screen is tapped */
695 document.body.addEventListener("click", swap_colors);
696 }
697
698 </script>
699 </body>
700 </html>