This repository has been archived by the owner on Dec 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
site.template.html
461 lines (374 loc) · 18.4 KB
/
site.template.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="Referrer-Policy" value="no-referrer | same-origin"/>
<title>Covid-19 Screener</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<style>
html {
scroll-behavior: smooth;
}
</style>
<link rel="stylesheet" href="{base_url}assets/css/themes.css">
<script async type="text/javascript" src="https://dap.digitalgov.gov/Universal-Federated-Analytics-Min.js?agency=VA" id="_fed_an_ua_tag"></script>
<!-- Favicons
================================================== -->
<link href="https://prod-va-gov-assets.s3-us-gov-west-1.amazonaws.com/img/design/icons/apple-touch-icon.png" rel="apple-touch-icon-precomposed">
<link href="https://prod-va-gov-assets.s3-us-gov-west-1.amazonaws.com/img/design/icons/apple-touch-icon-72x72.png" rel="apple-touch-icon-precomposed" sizes="72x72">
<link href="https://prod-va-gov-assets.s3-us-gov-west-1.amazonaws.com/img/design/icons/apple-touch-icon-114x114.png" rel="apple-touch-icon-precomposed" sizes="114x114">
<link href="https://prod-va-gov-assets.s3-us-gov-west-1.amazonaws.com/img/design/icons/apple-touch-icon-152x152.png" rel="apple-touch-icon-precomposed" sizes="144x144">
<link rel="shortcut icon" href="https://prod-va-gov-assets.s3-us-gov-west-1.amazonaws.com/img/design/icons/favicon.ico">
</head>
<body>
<section class="site-banner usa-banner" aria-label="Official government website">
<link rel="stylesheet" href="{base_url}assets/css/uswds.css" media="none" onload="if(media!='all')media='all'">
<script async src="{base_url}assets/js/uswds.min.js"></script>
<div class="usa-accordion">
<header class="usa-banner__header">
<div class="usa-banner__inner">
<div class="grid-col-auto">
<img class="usa-banner__header-flag" src="{base_url}assets/img/us_flag_small.png" alt="U.S. flag">
</div>
<div class="grid-col-fill tablet:grid-col-auto">
<p class="usa-banner__header-text">An official website of the United States government</p>
<p tabindex = "-1" class="usa-banner__header-action">Here’s how you know</p>
</div>
<button class="usa-accordion__button usa-banner__button"
aria-expanded="false" aria-controls="gov-banner">
<span class="usa-banner__button-text">Here's how you know</span>
</button>
</div>
</header>
<div class="usa-banner__content usa-accordion__content" id="gov-banner">
<div class="grid-row grid-gap-lg">
<div class="usa-banner__guidance tablet:grid-col-6">
<img class="usa-banner__icon usa-media-block__img" src="{base_url}assets/img/icon-dot-gov.svg" alt="Dot gov">
<div class="usa-media-block__body">
<p>
<strong>The .gov means it’s official.</strong>
<br>
Federal government websites often end in .gov or .mil. Before sharing sensitive information, make sure you’re on a federal government site.
</p>
</div>
</div>
<div class="usa-banner__guidance tablet:grid-col-6">
<img class="usa-banner__icon usa-media-block__img" src="{base_url}assets/img/icon-https.svg" alt="Https">
<div class="usa-media-block__body">
<p>
<strong>The site is secure.</strong>
<br>
The <strong>https://</strong> ensures that you are connecting to the official website and that any information you provide is encrypted and transmitted securely.
</p>
</div>
</div>
</div>
</div>
</div>
</section>
<div id="top_hdr" class="container-fluid" style="border-bottom:1px solid lightgray">
<img role="banner" id="top_hdr_img" alt="agency logo" src="" style="margin: 1em 0.5em 0.5em 0em;max-width:60%;
height:auto;">
</div>
<div role="main">
<h1 id="top_hdr_info" tabindex="0" class="container-fluid text-center" style="font-size: 1.3em;">
Covid 19 Screening Tool
</h1>
</div>
<div id="top_statement" role="complementary" class="mt-4 container-fluid text-left"> Please answer the questions listed below. <br>
<strong>We won't store or share your data.</strong><br>
Accessibility note: JAWS Virtual Cursor required</div>
<div id="top_el" role="application" class="container mt-4">
</div>
<div id="bottom_ftr_info" role="contentinfo" class="text-white bg-primary font-weight-light container-fluid text-center mt-4 mb-4">
<small>Thank you for helping us protect you and others during this time. Please note we won't store or share your data.</small>
</div>
</body>
</html>
<script>
function apply_variables_in_text(text_in) {
let vars = ['$DATETIME'];
let t = "";
let r = "";
t = text_in;
r = text_in;
vars.forEach((v) => {
if(t.includes(v)) {
if(v === '$DATETIME'){
let day = new Date().toLocaleString('en-us', { weekday: 'long' });
let date = new Date().toLocaleString('en-us', { date: 'short' });
r = t.replace(v, day + "<br>" + date);
}
}
});
return r;
}
function apply_weekday_theme_to_card(header_card_el, fac_json) {
let previous_bk_color = header_card_el.style.backgroundColor;
let previous_fg_color = header_card_el.style.color;
try {
if(fac_json.hasOwnProperty('weekday_card_bg_color_array') &&
fac_json.hasOwnProperty('weekday_card_text_color_array')) {
let d = new Date();
let weekday = d.getDay();
console.log('applying weekday theme for day: ' + weekday);
header_card_el.style.backgroundColor = fac_json.weekday_card_bg_color_array[weekday - 1];
header_card_el.style.color = fac_json.weekday_card_text_color_array[weekday - 1];
}
else
console.log('no data to apply weekday theme ');
} catch (e) {
// restore
console.log('error applying weekday theme: ' + e.message);
header_card_el.style.backgroundColor = previous_bk_color;
header_card_el.style.color = previous_fg_color;
}
}
function create_card_element(id, card_header, card_body, card_footer, card_btns, theme_string)
{
let el = document.createElement("DIV");
let hdr_id = id + "-hdr";
let bdy_id = id + "-bdy";
el.className = theme_string + " card text-center mt-5";
el.id = id;
el.setAttribute("role","dialog");
document.querySelectorAll("div.card");
// console.log('card theme classes: ' + theme_string);
if(card_header!=="") {
el.setAttribute("aria-labelledby",hdr_id);
let hdr = document.createElement("DIV");
hdr.className = "card-header bg-dark text-light";
hdr.innerHTML = card_header;
hdr.id = hdr_id;
el.appendChild(hdr);
}
if(card_body!=="") {
el.setAttribute("aria-describedby",bdy_id);
let bdy = document.createElement("DIV");
bdy.className = "card-body";
bdy.innerHTML = card_body;
if(card_body.length>700)
bdy.style.fontSize = "70%"
bdy.id = bdy_id;
el.appendChild(bdy);
if(card_btns.length > 0)
{
card_btns.forEach(element => {
let row = document.createElement("DIV");
row.className = "card-row text-center mb-2";
el.appendChild(row);
row.appendChild(element);
});
}
}
if(card_footer!=="")
{
let ftr = document.createElement("DIV");
ftr.className = "card-footer";
ftr.innerHTML = card_footer;
ftr.id = el.id + "-ftr"
el.appendChild(ftr);
}
if(theme_string === "weekday") {
apply_weekday_theme_to_card(el);
}
return el;
}
function handler_next(called_by, flow, next_flow_el, all_buttons) {
if(next_flow_el==="") {
// reset
let node = document.getElementById("top_el");
// ie11/es5 fix
try {
node.querySelectorAll('*').forEach(n => n.remove());
} catch(e) {
node.querySelectorAll('*').forEach(
function(n, i) { n.remove(); });
}
setTimeout(handler_next(undefined, flow, first_flow_el), 500);
return;
}
// v2:
let flow_el = flow[next_flow_el];
if(flow_el === undefined)
{
console.log('Unknown flow element: ' + next_flow_el)
return;
}
if(called_by !== undefined){
let parent = document.getElementById('top_el');
// TODO: more than two sibling buttons
let sibling_div = called_by.parentElement.nextSibling === null ? called_by.parentElement.previousSibling:called_by.parentElement.nextSibling;
let sibling_btn = undefined;
if(sibling_div.lastElementChild) {
if( sibling_div.lastElementChild.tagName === "BUTTON")
{
sibling_btn = sibling_div.lastElementChild;
}
}
if(called_by.classList.contains('button-white')) {
called_by.classList.toggle( "button-white" );
called_by.classList.toggle( "button-blue" );
called_by.setAttribute("aria-pressed", "true"); // v2 -
if(sibling_btn !== undefined) {
sibling_btn.setAttribute("aria-pressed", "false"); // v2 -
if(sibling_btn.classList.contains('button-blue')) {
sibling_btn.classList.toggle( "button-white" );
sibling_btn.classList.toggle( "button-blue" );
}
}
}
while(parent.lastElementChild && parent.lastElementChild !== called_by.parentElement.parentElement) {
parent.removeChild(parent.lastElementChild);
}
}
let card_hdr = "";
let card_bdy = "";
let card_ftr = "";
let card_btns = [];
let card_id = "card-" + next_flow_el;
let state_theme = flow_el.theme;
let flow_el_text = apply_variables_in_text(flow_el.text);
if(flow_el.type === "statement") {
let nxt = flow_el.next;
card_bdy = flow_el_text;
card_hdr = flow_el.short;
card_ftr = "";
if(nxt !== undefined && nxt!=="" && nxt !== "end")
{
let btn = document.createElement("BUTTON");
btn.textContent=`Next`;
btn.className = "button-general button-white "; //"btn btn-primary mb-2 mr-2";
btn.tabIndex = 0;
// btn.id = id;
btn.addEventListener("click", function() { handler_next(btn, flow, nxt, [btn]); }, false);
card_btns.push(btn);
}
else {// last element
if(nxt !== "end") {
let btn = document.createElement("BUTTON");
btn.textContent=`Reset`;
btn.className = "button-general button-white"; //"btn btn-primary mb-2 mr-2";
btn.tabIndex = 0;
// btn.id = id;
btn.addEventListener("click", function() { handler_next(btn, flow, nxt, [btn]); }, false);
card_btns.push(btn);
}
}
}
else if(flow_el.type === "bool_decision") {
let nxt_yes = flow_el.yes;
let nxt_no = flow_el.no;
card_bdy = flow_el_text;
card_hdr = flow_el.short;
card_ftr = "";
if(nxt_yes !== undefined && nxt_no !== undefined)
{
let yes_btn = document.createElement("BUTTON");
yes_btn.textContent=`Yes`;
yes_btn.className = "button-general button-white" ; //"btn btn-primary mb-2 mr-2";
yes_btn.tabIndex = 0;
// yes_btn.id = nxt_yes;
yes_btn.setAttribute("aria-pressed", "false"); // v2 - set intentionally
//yes_btn.setAttribute("aria-describedby", card_id);
let no_btn = document.createElement("BUTTON");
no_btn.textContent=`No`;
no_btn.className = "button-general button-white"; //"btn btn-primary mb-2 mr-2";
no_btn.tabIndex = 0;
// no_btn.id = nxt_no;
no_btn.setAttribute("aria-pressed", "false");
yes_btn.addEventListener("click", function() { handler_next(yes_btn, flow, nxt_yes, [yes_btn, no_btn]); }, false);
// success metric 4.1.2
yes_btn.addEventListener("keydown", function(event) {
if(event.keyCode == 32 || event.keyCode == 13) {
handler_next(yes_btn, flow, nxt_yes, [yes_btn, no_btn]);
}
}, false
);
card_btns.push(yes_btn);
no_btn.addEventListener("click", function() { handler_next(no_btn, flow, nxt_no, [yes_btn, no_btn]); }, false);
// success metric 4.1.2
no_btn.addEventListener("keydown", function(event) {
if(event.keyCode == 32 || event.keyCode == 13) {
handler_next(no_btn, flow, nxt_no, [yes_btn, no_btn]);
}
}, false
);
card_btns.push(no_btn);
}
}
let new_el = create_card_element(next_flow_el, card_hdr, card_bdy, card_ftr, card_btns, state_theme);
document.getElementById('top_el').appendChild(new_el);
// document.getElementById('bottom_ftr_info').scrollIntoView(false);
if(called_by === undefined)
document.getElementById('top_hdr').scrollIntoView(false);
else
// it is not the first element
// new_el.scrollIntoView(false); // this is not making the bottom statement visible
document.getElementById('bottom_ftr_info').scrollIntoView(false);
}
// this function is used when something goes wrong
function show_exceptions(hdr, bdy, ftr) {
let new_el = create_card_element("starting", hdr, bdy, ftr, [], "red");
// remove if there is already one
if(document.getElementById(new_el.id)!==null)
document.getElementById('top_el').textContent = "";
document.getElementById('top_el').appendChild(new_el);
}
function setup_header(fac_json) {
document.getElementById('top_hdr_img').src = fac_json.image;
document.getElementById('top_hdr_img').alt = fac_json.image_desc;
document.getElementById('top_hdr').style.backgroundColor = fac_json.header_color;
document.getElementById('top_hdr').style.color = fac_json.header_text_color;
document.getElementById('top_hdr_info').textContent = fac_json.name;
}
function setup_body_color(fac_json) {
if(fac_json.hasOwnProperty('weekday_background_color_array') &&
fac_json.hasOwnProperty('weekday_text_color_array'))
{
let bg_color = '#ffffff';
let fg_color = '#000000';
try {
let d = new Date();
let d_of_wk = d.getDay();
bg_color = fac_json.weekday_background_color_array[d_of_wk - 1];
fg_color = fac_json.weekday_text_color_array[d_of_wk - 1];
}
catch(e) {
console.log('Error setting up bg color: ' + e.message);
}
document.getElementsByTagName('body')[0].style.backgroundColor = bg_color;
document.getElementsByTagName('body')[0].style.color = fg_color;
// console.log('Setting up colors for the weekday: ' + bg_color + '/' + fg_color);
}
}
function setup_facility(fac_json) {
setup_header(fac_json);
setup_body_color(fac_json);
}
function is_enabled(fac_json) {
if(fac_json.flow_enabled === false)
{
return false;
}
if(Date.parse(fac_json.effective_from) > Date.now()
|| Date.parse(fac_json.effective_till) < Date.now())
{ // Screening protocol is not active today
return false;
}
return true;
}
function default_loop() {
let facilitydata = [{facility_json_array_element}]; // variable that will be replaced by the federalist site generator
let flows = [{flow_json_array_element}]; // variable that will be replaced by the federalist site generator
let flowchart = flows[0].flow;
console.log('BaseURL: ' + '{base_url}');
setup_facility(facilitydata[0]);
handler_next(undefined, flowchart, first_flow_el);
}
// federalist version of the site
var first_flow_el = "start";
default_loop();
</script>