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");
293 /* First, find the center of the red box */
294 const r1 = document.getElementById("codebg").getBoundingClientRect();
295 const c1 = r1.left + (r1.width /
2);
297 /* Now the center of the code text */
298 const r2 = ct.getBoundingClientRect();
299 const c2 = r2.left + (r2.width /
2);
301 /* What do we add to c2 to make it equal to c1? */
302 const hdelta = c1 - c2;
304 /* Since this
<text> element has an "x" attribute it's easier for
305 * us to shift that than it is to mess with the "left" style. */
306 ct.setAttribute("x", parseFloat(ct.getAttribute("x")) + hdelta);
309 function center_code_wrapper() {
310 /* Lets us call center_code twice on page load. Why we need to
311 * do this is an interesting (i.e. stupid) conversation. */
315 /*****************************************/
316 /* Next, set up the ticket date and time */
317 /*****************************************/
319 function set_ticket_expiry() {
320 /* There are two parameters, time and date, that we store in one
321 * underlying "date" variable. Default both to an hour and a
322 * half from now. This is what the CharmPass app does for
323 * one-way tickets. */
324 const date = new Date();
326 /* Add an hour and a half. We use the low-level get/setTime to
327 * change the number of milliseconds since the epoch that this
328 * date represents. Obviously correct, and avoids all suspicious
329 * corner cases (well, for a few more decades). */
330 date.setTime(date.getTime() + (
90*
60*
1000));
332 tt = document.getElementById("tickettime");
333 tt.textContent = date.toLocaleTimeString();
335 const td = document.getElementById("ticketdate");
341 td.textContent = date.toLocaleDateString("en-US", dateopts);
345 /*********************************************************/
346 /* Finally, the onclick handler for the night/day switch */
347 /*********************************************************/
349 /* We always start in "day" mode */
353 sky.style.fill = "#efb02f";
356 function set_night() {
357 sky.style.fill = "#
143b66";
360 function swap_colors() {
372 /*****************************************************/
373 /* Add event handlers for all of the functions above */
374 /*****************************************************/
376 /* Center the ticket once when the page has loaded */
377 window.addEventListener("load", center_ticket);
379 /* Re-center the ticket when the window is resized */
380 window.addEventListener("resize", center_ticket);
382 /* Set the security code text when the page has loaded */
383 window.addEventListener("load", set_code);
385 /* Center the security code text when the page has loaded;
386 * in particular, after we set it. And then center it again.
387 * Why? I'm glad you asked. Because it doesn't actually get
388 * centered the first time; it's off by a few pixels. But then
389 * if we center it _again_, I guess we're so close to begin with
390 * that any errors aren't noticeable. Anyway, just running it
391 * twice in a row avoids a major headache. We need the wrapper
392 * because the spec says that duplicate handlers are discarded. */
393 window.addEventListener("load", center_code);
394 window.addEventListener("load", center_code_wrapper);
396 /* Re-center the security code when the window is resized,
397 * and in particular after the ticket is re-centered */
398 window.addEventListener("resize", center_code);
400 /* Set the ticket expiration date/time upon page load */
401 window.addEventListener("load", set_ticket_expiry);
403 /* Swap colors when the screen is tapped */
404 document.body.addEventListener("click", swap_colors);