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;
88 /************************/
89 /* Scrolling animations */
90 /************************/
95 transform: translateX(
0%);
98 transform: translateX(
100%);
103 animation: busroll
23s linear infinite;
108 @keyframes tramroll {
110 transform: translateX(
0%);
113 transform: translateX(
100%);
118 animation: tramroll
17s linear infinite;
123 @keyframes trainroll {
125 transform: translateX(
0%);
128 transform: translateX(
100%);
133 animation: trainroll
11s linear infinite;
138 @keyframes cloudsfloat {
140 transform: translateX(
0%);
143 transform: translateX(-
50%);
148 animation: cloudsfloat
40s linear infinite;
151 @keyframes cloudscopyfloat {
153 transform: translateX(
0%);
156 transform: translateX(-
50%);
161 animation: cloudscopyfloat
40s linear infinite;
166 @keyframes treespass {
168 transform: translateX(
0%);
171 transform: translateX(-
50%);
176 /* The trees move a little faster than the clouds */
177 animation: treespass
30s linear infinite;
180 @keyframes treescopypass {
182 transform: translateX(
0%);
185 transform: translateX(-
50%);
190 /* The trees move a little faster than the clouds */
191 animation: treescopypass
30s linear infinite;
196 @keyframes cityscroll {
198 transform: translateX(
0%);
201 transform: translateX(-
50%);
206 /* The city moves faster than the clouds but slower
208 animation: cityscroll
35s linear infinite;
211 @keyframes citycopyscroll {
213 transform: translateX(
0%);
216 transform: translateX(-
50%);
221 /* The city moves faster than the clouds but slower
223 animation: citycopyscroll
35s linear infinite;
233 /***********************************************/
234 /* First, center the ticket within the browser */
235 /***********************************************/
237 function center_ticket() {
238 /* We're relying on the SVG being the full height of the
239 * viewport already, and on the aspect ratio being
240 * preserved. First, find the center of the ticket. */
241 const r = document.getElementById("ticket").getBoundingClientRect();
242 const c = r.left + (r.width /
2);
244 /* That's the center-line of the ticket. We want to move it to
245 * the center-line of the viewport. */
246 const vc = document.documentElement.clientWidth /
2;
248 /* This is how much we need to translate the SVG */
249 const hdelta = vc - c;
251 /* But before we can set the absolute left-coordinate of the
252 * SVG, we need to know where it is now. Note: without the
253 * "px" this doesn't default to pixels like CSS does. */
254 const svg = document.querySelector("svg");
255 svg.style.left = (svg.getBoundingClientRect().left + hdelta) + "px";
259 /****************************************/
260 /* Set and reposition the security code */
261 /****************************************/
263 function set_code() {
264 const ct = document.getElementById("codetext");
266 /* Get the "code" from the querystring if it's there */
267 let params = new URLSearchParams(document.location.search);
268 if (params.get("code")) {
269 ct.textContent = params.get("code");
272 /* Otherwise, use a random code */
273 const bucket = ["
0","
1","
2","
3","
4","
5","
6","
7","
8","
9",
274 "A","B","C","D","E","F","G","H","I","J",
275 "K","L","M","N","O","P","Q","R","S","T",
276 "U","V","W","X","Y","Z"];
278 /* Two random ints between
0 and
35 */
279 const i1 = Math.floor(Math.random() *
36);
280 const i2 = Math.floor(Math.random() *
36);
281 const d1 = bucket[i1];
282 const d2 = bucket[i2];
283 ct.textContent = d1 + d2;
288 function center_code() {
289 /* Center the security code inside its red box */
290 const ct = document.getElementById("codetext");
292 /* First, find the center of the red box */
293 const r1 = document.getElementById("codebg").getBoundingClientRect();
294 const c1 = r1.left + (r1.width /
2);
296 /* Now the center of the code text */
297 const r2 = ct.getBoundingClientRect();
298 const c2 = r2.left + (r2.width /
2);
300 /* What do we add to c2 to make it equal to c1? */
301 const hdelta = c1 - c2;
303 /* Since this
<text> element has an "x" attribute it's easier for
304 * us to shift that than it is to mess with the "left" style. */
305 ct.setAttribute("x", parseFloat(ct.getAttribute("x")) + hdelta);
309 /*****************************************/
310 /* Next, set up the ticket date and time */
311 /*****************************************/
313 function set_ticket_expiry() {
314 /* There are two parameters, time and date, that we store in one
315 * underlying "date" variable. Default both to an hour and a
316 * half from now. This is what the CharmPass app does for
317 * one-way tickets. */
318 const date = new Date();
320 /* Add an hour and a half. We use the low-level get/setTime to
321 * change the number of milliseconds since the epoch that this
322 * date represents. Obviously correct, and avoids all suspicious
323 * corner cases (well, for a few more decades). */
324 date.setTime(date.getTime() + (
90*
60*
1000));
326 tt = document.getElementById("tickettime");
327 tt.textContent = date.toLocaleTimeString();
329 const td = document.getElementById("ticketdate");
335 td.textContent = date.toLocaleDateString("en-US", dateopts);
339 /*********************************************************/
340 /* Finally, the onclick handler for the night/day switch */
341 /*********************************************************/
343 /* We always start in "day" mode */
347 sky.style.fill = "#efb02f";
350 function set_night() {
351 sky.style.fill = "#
143b66";
354 function swap_colors() {
366 /*****************************************************/
367 /* Add event handlers for all of the functions above */
368 /*****************************************************/
370 /* Center the ticket once when the page has loaded */
371 window.addEventListener("load", center_ticket);
373 /* Re-center the ticket when the window is resized */
374 window.addEventListener("resize", center_ticket);
376 /* Set the security code text when the page has loaded */
377 window.addEventListener("load", set_code);
379 /* Center the security code text when the page has loaded;
380 in particular, after we set it */
381 window.addEventListener("load", center_code);
383 /* Re-center the security code when the window is resized,
384 and in particular after the ticket is re-centered */
385 window.addEventListener("resize", center_code);
387 /* Set the ticket expiration date/time upon page load */
388 window.addEventListener("load", set_ticket_expiry);
390 /* Swap colors when the screen is tapped */
391 document.body.addEventListener("click", swap_colors);