4 <meta name=
"viewport" content=
"width=device-width, initial-scale=1" />
12 * Reset styles for the html and body elements, the only two HTML
24 text-decoration: none;
25 vertical-align: baseline;
26 background: transparent;
30 /* To create our "window" onto the scene, we're going to slide the
31 * SVG off the left-hand side of the screen, and we don't want
32 * scroll bars to appear. */
37 /* Set the height to
100% of the screen, which we'll keep; and the
38 * initial position to (
0,
0), which we're going to change
39 * every time the window is resized, because the exact amount
40 * that we have to slide the SVG to the left to get the ticket
41 * into the center will change. */
48 /* The blinking fade in/out animation for the ticket date and time */
61 #tickettime, #ticketdate {
62 /*
300 two-second blinks is ten minutes */
63 animation: blink
2s linear
300;
66 /* Define, load, and specify the custom font we use for the ticket
67 * date, time, and service name. */
69 font-family: "CharmBypass Regular";
71 url("data:font/woff2;base64,@CBPREGULAR@") format("woff2")
74 #servicename, #tickettime, #ticketdate, #codetext {
75 font-family: "CharmBypass Regular", sans-serif;
79 font-family: "CharmBypass Bold";
81 url("data:font/woff2;base64,@CBPBOLD@") format("woff2")
85 font-family: "CharmBypass Bold", sans-serif;
89 /************************/
90 /* Scrolling animations */
91 /************************/
96 transform: translateX(
0%);
99 transform: translateX(-
100%);
104 animation: busroll
23s linear infinite;
109 @keyframes tramroll {
111 transform: translateX(
0%);
114 transform: translateX(
100%);
119 animation: tramroll
17s linear infinite;
124 @keyframes trainroll {
126 transform: translateX(
0%);
129 transform: translateX(
100%);
134 animation: trainroll
11s linear infinite;
139 @keyframes cloudsfloat {
141 transform: translateX(
0%);
144 transform: translateX(-
50%);
149 animation: cloudsfloat
40s linear infinite;
152 @keyframes cloudscopyfloat {
154 transform: translateX(
0%);
157 transform: translateX(-
50%);
162 animation: cloudscopyfloat
40s linear infinite;
167 @keyframes treespass {
169 transform: translateX(
0%);
172 transform: translateX(-
50%);
177 /* The trees move a little faster than the clouds */
178 animation: treespass
30s linear infinite;
181 @keyframes treescopypass {
183 transform: translateX(
0%);
186 transform: translateX(-
50%);
191 /* The trees move a little faster than the clouds */
192 animation: treescopypass
30s linear infinite;
197 @keyframes cityscroll {
199 transform: translateX(
0%);
202 transform: translateX(-
50%);
207 /* The city moves faster than the clouds but slower
209 animation: cityscroll
35s linear infinite;
212 @keyframes citycopyscroll {
214 transform: translateX(
0%);
217 transform: translateX(-
50%);
222 /* The city moves faster than the clouds but slower
224 animation: citycopyscroll
35s linear infinite;
234 /***********************************************/
235 /* First, center the ticket within the browser */
236 /***********************************************/
238 function center_ticket() {
239 /* We're relying on the SVG being the full height of the
240 * viewport already, and on the aspect ratio being
241 * preserved. First, find the center of the ticket. */
242 const r = document.getElementById("ticket").getBoundingClientRect();
243 const c = r.left + (r.width /
2);
245 /* That's the center-line of the ticket. We want to move it to
246 * the center-line of the viewport. */
247 const vc = document.documentElement.clientWidth /
2;
249 /* This is how much we need to translate the SVG */
250 const hdelta = vc - c;
252 /* But before we can set the absolute left-coordinate of the
253 * SVG, we need to know where it is now. Note: without the
254 * "px" this doesn't default to pixels like CSS does. */
255 const svg = document.querySelector("svg");
256 svg.style.left = (svg.getBoundingClientRect().left + hdelta) + "px";
260 /****************************************/
261 /* Set and reposition the security code */
262 /****************************************/
264 function set_code() {
265 const ct = document.getElementById("codetext");
267 /* Get the "code" from the querystring if it's there */
268 let params = new URLSearchParams(document.location.search);
269 if (params.get("code")) {
270 ct.textContent = params.get("code");
273 /* Otherwise, use a random code */
274 const bucket = ["
0","
1","
2","
3","
4","
5","
6","
7","
8","
9",
275 "A","B","C","D","E","F","G","H","I","J",
276 "K","L","M","N","O","P","Q","R","S","T",
277 "U","V","W","X","Y","Z"];
279 /* Two random ints between
0 and
35 */
280 const i1 = Math.floor(Math.random() *
36);
281 const i2 = Math.floor(Math.random() *
36);
282 const d1 = bucket[i1];
283 const d2 = bucket[i2];
284 ct.textContent = d1 + d2;
289 function center_code() {
290 /* Center the security code inside its red box */
291 const ct = document.getElementById("codetext");
292 const bg = document.getElementById("codebg");
294 /* First, find the center of the red box */
295 const r1 = bg.getBoundingClientRect();
296 const c1 = r1.left + (r1.width /
2);
298 /* Now the center of the code text */
299 const r2 = ct.getBoundingClientRect();
300 const c2 = r2.left + (r2.width /
2);
302 /* What do we add to c2 to make it equal to c1? */
303 const hdelta = c1 - c2;
305 /* We've measured everything so far in "client rect"
306 * coordinates, because that's the only available measurement
307 * we have for the width of the
<text> element after futzing
308 * with its contents. But when we reposition that
<text>
309 * element, it will be by adjusting its "x" attribute, and
310 * that attribute uses a different coordinate system than the
311 * client rect does. Specifically, "x" refers to an offset
312 * within the SVG's coordinate system, and the client rect
313 * coordinates are pixels on-screen. To convert between the
314 * two, we can take the "width" attribute of the background
315 * element and compare it to the width of the background
316 * element's client rect. Since the size of the background is
317 * fixed, this should give us a multiplier that turns client recr
318 * distances (what we have) into SVG distances (what we want) */
319 const client_to_svg = parseFloat(bg.getAttribute("width"))/r1.width;
321 /* Convert hdelta from client rect to SVG coordinates */
322 const svg_hdelta = hdelta * client_to_svg;
324 /* Since this
<text> element has an "x" attribute it's easier for
325 * us to shift that than it is to mess with the "left" style. */
326 ct.setAttribute("x", parseFloat(ct.getAttribute("x")) + svg_hdelta);
329 /*****************************************/
330 /* Next, set up the ticket date and time */
331 /*****************************************/
333 function set_ticket_expiry() {
334 /* There are two parameters, time and date, that we store in one
335 * underlying "date" variable. Default both to an hour and a
336 * half from now. This is what the CharmPass app does for
337 * one-way tickets. */
338 const date = new Date();
340 /* Add an hour and a half. We use the low-level get/setTime to
341 * change the number of milliseconds since the epoch that this
342 * date represents. Obviously correct, and avoids all suspicious
343 * corner cases (well, for a few more decades). */
344 date.setTime(date.getTime() + (
90*
60*
1000));
346 tt = document.getElementById("tickettime");
347 tt.textContent = date.toLocaleTimeString();
349 const td = document.getElementById("ticketdate");
355 td.textContent = date.toLocaleDateString("en-US", dateopts);
359 /*********************************************************/
360 /* Finally, the onclick handler for the night/day switch */
361 /*********************************************************/
363 /* We always start in "day" mode */
367 sky.style.fill = "#efb02f";
370 function set_night() {
371 sky.style.fill = "#
143b66";
374 function swap_colors() {
386 /*****************************************************/
387 /* Add event handlers for all of the functions above */
388 /*****************************************************/
390 /* Center the ticket once when the page has loaded */
391 window.addEventListener("load", center_ticket);
393 /* Re-center the ticket when the window is resized */
394 window.addEventListener("resize", center_ticket);
396 /* Set the security code text when the page has loaded */
397 window.addEventListener("load", set_code);
399 /* Center the security code text when the page has loaded; in
400 * particular, after we set the code. */
401 window.addEventListener("load", center_code);
403 /* Set the ticket expiration date/time upon page load */
404 window.addEventListener("load", set_ticket_expiry);
406 /* Swap colors when the screen is tapped */
407 document.body.addEventListener("click", swap_colors);