-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproto.js
More file actions
54 lines (42 loc) · 1.56 KB
/
proto.js
File metadata and controls
54 lines (42 loc) · 1.56 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
const dataUrl = 'https://dcooke28.github.io/tbots/proto.json';
const pageTitle = document.getElementById('pageTitle');
const pageDescription = document.getElementById('pageDescription');
const itemSiteNumber = document.getElementById('siteNumber');
const itemTransect = document.getElementById('transect');
const itemShovelTestNumber = document.getElementById('shovelTestNumber');
const itemUtm = document.getElementById('utm');
const itemStratumBaseDepth = document.getElementById('stratumBaseDepth');
const photo = document.getElementById('photo');
function displayItemPage(data, id) {
const item = data.find(i => i.id == id);
pageTitle.textContent = item.name;
pageDescription.textContent = item.details;
itemSiteNumber.textContent = item.site_number;
itemTransect.textContent = item.transect;
itemShovelTestNumber.textContent = item.shovel_test_number;
itemUtm.textContent = item.utm;
itemStratumBaseDepth.textContent = item.stratum_base_depth;
photo.src = item.photo;
}
function getItemIdFromQuery() {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get('id');
}
async function loadData() {
const response = await fetch(dataUrl);
if (!response.ok) {
throw new Error(`Load data error - status ${response.status}`);
}
const data = await response.json();
const itemId = getItemIdFromQuery();
if (!itemId) {
// display standard page
} else {
displayItemPage(data, itemId);
}
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', loadData);
} else {
loadData();
}