-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtracker-basic.html
More file actions
564 lines (496 loc) · 15.8 KB
/
Copy pathtracker-basic.html
File metadata and controls
564 lines (496 loc) · 15.8 KB
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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SunSmart Basic UV Tracker</title>
<link rel="icon" type="image/x-icon" href="logo.ico">
<link rel="icon" type="image/png" href="SUN SMART.png">
<link rel="icon" type="image/png" href="logo.png">
<link rel="icon" type="image/jpeg" href="logo.jpg">
<link rel="icon" type="image/jpeg" href="logo.jpeg">
<link rel="icon" type="image/webp" href="logo.webp">
<style>
* {
box-sizing: border-box;
}
html {
background: #fff;
}
body {
margin: 0;
min-height: 100vh;
font-family: Arial, Helvetica, sans-serif;
color: #111;
background: #fff;
}
.navbar {
position: sticky;
top: 0;
z-index: 10;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
width: 100%;
padding: 14px clamp(22px, 5vw, 56px);
border-bottom: 1px solid rgba(111, 82, 47, 0.28);
background: rgba(255, 252, 245, 0.96);
backdrop-filter: blur(12px);
box-shadow: 0 10px 28px rgba(79, 54, 31, 0.12);
}
.nav-brand {
display: flex;
align-items: center;
gap: 10px;
color: #111;
font-size: 18px;
font-weight: 800;
text-decoration: none;
}
.nav-logo {
width: 38px;
height: 38px;
object-fit: contain;
}
.nav-links {
display: flex;
gap: 8px;
align-items: center;
padding: 6px;
border: 1px solid rgba(0, 0, 0, 0.12);
border-radius: 8px;
background: #fbf5ea;
}
.nav-links a,
.nav-trigger {
width: auto;
padding: 9px 12px;
border: 0;
border-radius: 6px;
color: #111;
background: transparent;
font: inherit;
font-weight: 700;
text-decoration: none;
cursor: pointer;
transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}
.nav-links a:hover,
.nav-dropdown:hover .nav-trigger,
.nav-dropdown:focus-within .nav-trigger {
background: #efe2cc;
color: #111;
}
.nav-links a.active {
background: #7d6848;
color: #fff;
}
.nav-dropdown {
position: relative;
margin-left: 4px;
}
.nav-menu {
position: absolute;
top: 100%;
right: 0;
z-index: 20;
display: none;
min-width: 190px;
padding: 6px;
border: 1px solid rgba(111, 82, 47, 0.18);
border-radius: 8px;
background: #fffaf1;
box-shadow: 0 16px 40px rgba(79, 54, 31, 0.16);
}
.nav-dropdown:hover .nav-menu,
.nav-dropdown:focus-within .nav-menu,
.nav-dropdown.open .nav-menu {
display: grid;
gap: 4px;
}
.nav-menu a {
display: block;
white-space: nowrap;
}
main {
width: min(760px, 100%);
margin: 0 auto;
padding: 52px 20px;
}
.site-logo {
display: block;
width: 96px;
height: 96px;
margin-bottom: 18px;
object-fit: contain;
}
h1 {
margin: 0 0 12px;
font-size: 42px;
line-height: 1.08;
}
p {
margin: 0 0 28px;
color: #444;
font-size: 18px;
line-height: 1.5;
}
.tracker {
border: 1px solid #ddd;
border-radius: 8px;
padding: 26px;
background: #fff;
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.06);
}
label {
display: block;
margin-bottom: 8px;
font-weight: 700;
}
input,
select {
width: 100%;
margin-bottom: 18px;
padding: 13px 12px;
border: 1px solid #bbb;
border-radius: 6px;
font-size: 16px;
background: #fff;
}
button {
padding: 13px 18px;
border: 0;
border-radius: 6px;
color: #fff;
background: #111;
font-size: 16px;
font-weight: 800;
cursor: pointer;
}
button:hover {
background: #333;
}
.nav-trigger {
color: #111;
background: transparent;
font-size: inherit;
}
#cityPicker,
#rawSection {
display: none;
margin-top: 18px;
}
#result {
margin-top: 22px;
font-size: 18px;
font-weight: 700;
line-height: 1.5;
white-space: pre-line;
}
.checkbox-label {
display: flex;
gap: 8px;
align-items: center;
margin-top: 16px;
font-weight: 400;
}
.checkbox-label input {
width: auto;
margin: 0;
}
pre {
display: none;
overflow: auto;
padding: 14px;
border: 1px solid #ddd;
border-radius: 6px;
background: #fafafa;
font-size: 14px;
white-space: pre-wrap;
}
@media (max-width: 650px) {
.navbar {
align-items: flex-start;
flex-direction: column;
}
.nav-links {
flex-wrap: wrap;
}
.nav-menu {
right: auto;
left: 0;
}
h1 {
font-size: 34px;
}
}
.loading-screen {
position: fixed;
inset: 0;
z-index: 999;
display: grid;
place-items: center;
background: #fffaf1;
transition: opacity 320ms ease, visibility 320ms ease;
}
.loading-screen.hidden {
visibility: hidden;
opacity: 0;
pointer-events: none;
}
.loading-card {
display: grid;
justify-items: center;
gap: 16px;
color: #7d6848;
font-weight: 900;
letter-spacing: 0.02em;
text-align: center;
}
.loading-logo {
width: 108px;
height: 108px;
object-fit: contain;
animation: logoBounce 780ms ease-in-out infinite alternate;
filter: drop-shadow(0 18px 18px rgba(79, 54, 31, 0.18));
}
.loading-dots::after {
content: "";
animation: loadingDots 1.2s steps(4, end) infinite;
}
@keyframes logoBounce {
from {
transform: translateY(0) scale(1);
}
to {
transform: translateY(-22px) scale(1.04);
}
}
@keyframes loadingDots {
0% {
content: "";
}
25% {
content: ".";
}
50% {
content: "..";
}
75%,
100% {
content: "...";
}
}
@media (prefers-reduced-motion: reduce) {
.loading-logo {
animation: none;
}
}
</style>
</head>
<body>
<div id="loadingScreen" class="loading-screen hidden" aria-label="Loading SunSmart" aria-live="polite">
<div class="loading-card">
<img id="loadingLogo" class="loading-logo" src="SUN SMART.png" alt="SunSmart logo">
<div>Loading SunSmart<span class="loading-dots"></span></div>
</div>
</div>
<nav class="navbar">
<a class="nav-brand" href="index.html">
<img id="navLogo" class="nav-logo" src="SUN SMART.png" alt="SunSmart logo">
<span>SunSmart</span>
</a>
<div class="nav-links" aria-label="Main navigation">
<a href="index.html">Home</a>
<div class="nav-dropdown">
<button class="nav-trigger" type="button" aria-expanded="false" onclick="toggleNavMenu(event)">UV Tracker</button>
<div class="nav-menu">
<a href="tracker-basic.html">Basic Tracker</a>
<a class="active" href="tracker.html">Advanced Tracker</a>
</div>
</div>
</div>
</nav>
<main>
<img id="siteLogo" class="site-logo" src="SUN SMART.png" alt="SunSmart UV Tracker logo">
<h1>Basic UV Tracker</h1>
<p>Enter your city to get the current UV index and a quick sun safety reminder.</p>
<section class="tracker" aria-label="Basic UV tracker">
<label for="city">City</label>
<input id="city" type="text" placeholder="Example: Portland, OR">
<button type="button" onclick="checkUV()">Get UV Index</button>
<div id="cityPicker">
<label for="citySelect">Select your city:</label>
<select id="citySelect" onchange="fetchSelectedCityUV()"></select>
</div>
<div id="result" aria-live="polite"></div>
<div id="rawSection">
<label class="checkbox-label" for="showRaw">
<input id="showRaw" type="checkbox" onchange="toggleRawResponse()">
Show raw API response
</label>
<pre id="rawResponse"></pre>
</div>
</section>
</main>
<script>
const logoFiles = ["SUN SMART.png", "logo.ico", "logo.png", "logo.jpg", "logo.jpeg", "logo.webp"];
let candidates = [];
let rawApiResponse = null;
function loadLogoFor(elementId, index) {
const logo = document.getElementById(elementId);
if (!logo) return;
if (index >= logoFiles.length) {
logo.style.display = "none";
return;
}
logo.onerror = function() { loadLogoFor(elementId, index + 1); };
logo.src = logoFiles[index];
}
loadLogoFor("navLogo", 0);
loadLogoFor("siteLogo", 0);
function hideLoadingScreen() {
const loadingScreen = document.getElementById("loadingScreen");
if (!loadingScreen) return;
loadingScreen.classList.add("hidden");
}
function showLoadingScreen() {
const loadingScreen = document.getElementById("loadingScreen");
if (!loadingScreen) return;
loadingScreen.classList.remove("hidden");
}
window.addEventListener("DOMContentLoaded", hideLoadingScreen);
window.addEventListener("load", hideLoadingScreen);
setTimeout(hideLoadingScreen, 100);
function toggleNavMenu(event) {
const dropdown = event.currentTarget.closest(".nav-dropdown");
const isOpen = dropdown.classList.toggle("open");
event.currentTarget.setAttribute("aria-expanded", isOpen ? "true" : "false");
}
document.addEventListener("click", function(event) {
document.querySelectorAll(".nav-dropdown.open").forEach(function(dropdown) {
if (!dropdown.contains(event.target)) {
dropdown.classList.remove("open");
const trigger = dropdown.querySelector(".nav-trigger");
if (trigger) {
trigger.setAttribute("aria-expanded", "false");
}
}
});
});
async function checkUV() {
const cityInput = document.getElementById("city");
const result = document.getElementById("result");
const cityPicker = document.getElementById("cityPicker");
const rawSection = document.getElementById("rawSection");
const rawResponse = document.getElementById("rawResponse");
const showRaw = document.getElementById("showRaw");
const city = cityInput.value.trim();
if (city === "") {
result.textContent = "Please enter a city.";
return;
}
showLoadingScreen();
cityPicker.style.display = "none";
rawSection.style.display = "none";
rawResponse.style.display = "none";
showRaw.checked = false;
rawApiResponse = null;
result.textContent = "Looking up your city...";
try {
const searchUrl = "https://geocoding-api.open-meteo.com/v1/search?name=" + encodeURIComponent(city) + "&count=10&language=en&format=json";
const searchResponse = await fetch(searchUrl);
const searchData = await searchResponse.json();
const matchingCandidates = filterCandidates(searchData.results || [], city);
if (matchingCandidates.length === 0) {
result.textContent = "No results found. Try a more specific query like Portland, OR.";
hideLoadingScreen();
return;
}
candidates = matchingCandidates;
buildCitySelect();
cityPicker.style.display = "block";
await fetchSelectedCityUV();
} catch (error) {
result.textContent = "No results found. Check your connection or try a more specific city.";
hideLoadingScreen();
}
}
function buildCitySelect() {
const citySelect = document.getElementById("citySelect");
citySelect.innerHTML = "";
candidates.forEach(function(candidate, index) {
const option = document.createElement("option");
option.value = index;
option.textContent = cityLabel(candidate);
citySelect.appendChild(option);
});
}
function filterCandidates(results, city) {
const cityName = normalizeLocationName(city.split(",")[0] || city);
return results.filter(function(candidate) {
return normalizeLocationName(candidate.name || "") === cityName;
});
}
function normalizeLocationName(value) {
return String(value).trim().toLowerCase().replace(/[^a-z0-9 ]/g, "").replace(/\s+/g, " ");
}
async function fetchSelectedCityUV() {
const citySelect = document.getElementById("citySelect");
const result = document.getElementById("result");
const rawSection = document.getElementById("rawSection");
const showRaw = document.getElementById("showRaw");
const rawResponse = document.getElementById("rawResponse");
const choice = candidates[Number(citySelect.value)];
if (!choice) {
hideLoadingScreen();
return;
}
const label = cityLabel(choice);
const lat = Number(choice.latitude);
const lon = Number(choice.longitude);
showRaw.checked = false;
rawResponse.style.display = "none";
result.textContent = "You selected: " + label + "\nFetching current UV Index...";
try {
const uvUrl = "https://api.open-meteo.com/v1/forecast?latitude=" + lat + "&longitude=" + lon + "¤t=uv_index";
const uvResponse = await fetch(uvUrl);
const uvData = await uvResponse.json();
rawApiResponse = uvData;
rawSection.style.display = "block";
const uvi = uvData.current && uvData.current.uv_index;
if (uvi === undefined || uvi === null) {
result.textContent = "UV Index not found in response.";
hideLoadingScreen();
return;
}
result.textContent = "You selected: " + label + "\nCurrent UV Index: " + Number(uvi).toFixed(1) + "\n" + getTip(uvi);
} catch (error) {
result.textContent = "UV Index not found in response.";
}
hideLoadingScreen();
}
function cityLabel(candidate) {
const name = candidate.name || "";
const regionParts = [];
if (candidate.admin1) regionParts.push(candidate.admin1);
if (candidate.country) regionParts.push(candidate.country);
return name + (regionParts.length ? ", " + regionParts.join(", ") : "");
}
function getTip(uvi) {
if (uvi <= 2) return "Good! No protection needed; if you burn easily, use SPF 15+.";
if (uvi <= 5) return "Stay safe! Use SPF 30+, reapply every 2 hours, and seek shade when midday.";
if (uvi <= 7) return "Uh oh! Use SPF 50, reapply about every 2 hours, and seek shade at midday.";
return "Yikes! Use SPF 50+, reapply every 1.5 to 2 hours, and avoid midday sun.";
}
function toggleRawResponse() {
const showRaw = document.getElementById("showRaw");
const rawResponse = document.getElementById("rawResponse");
rawResponse.style.display = showRaw.checked ? "block" : "none";
rawResponse.textContent = showRaw.checked && rawApiResponse ? JSON.stringify(rawApiResponse, null, 2) : "";
}
</script>
<nav class="bottom-nav" style="position:fixed;left:0;right:0;bottom:0;height:56px;background:transparent;border-top:1px solid rgba(0,0,0,0.06);z-index:9999;" aria-hidden="true"></nav>
</body>
</html>