-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitemvisualisation.js
More file actions
188 lines (170 loc) · 6.25 KB
/
itemvisualisation.js
File metadata and controls
188 lines (170 loc) · 6.25 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
var items = []
var narratives = []
var currentSelection = []
var currentNarrative =""
var currentValue=""
var currentSort = ""
document.addEventListener("DOMContentLoaded", async function(event) {
console.log(" DO NOT PEEP o((>ω< ))o")
fetch('https://raw.githubusercontent.com/KodeKronicles/codechronicles.github.io/main/data.json')
.then(response => response.json())
.then(data => {
items = data.items
var startWith = data.meta.startWith
var item = items[startWith]
narratives = data.meta.narratives
currentNarrative = data.meta.startNarrative
currentValue = data.meta.startValue
prepareNarratives()
})
});
function prepareNarratives() {
currentSelection = items.filter( i =>
i.info["Type of device"]?.includes(currentNarrative)
)
currentSelection.sort( (i,j) =>
i['@sort'] < j['@sort'] ? -1 : 1
)
if (currentSelection.length==0)
currentSelection = items
var index = currentSelection.findIndex( i => i['@sort'] == currentSort )
if (index == -1) index = 0
showInfo(index)
}
function showInfo(index) {
var item = currentSelection[index]
currentSort = item['@sort']
inner("fullHeader",item.info.Name);
var imgdiv = byId("img1-div");
var imgpath = "url("+item.image1+")";
imgdiv.style.backgroundImage = imgpath;
//imgdiv.style.display = "block";
imgdiv.style.height = "100%";
imgdiv.style.width = "100%";
imgdiv.style.backgroundRepeat = "no-repeat";
imgdiv.style.backgroundSize = "100% auto";
var copyrightBox = byId("copyrightBox");
copyrightBox.innerText = item.copyright;
//byId("img1").src = item.image1
//byId("img1").alt = item.shortName
createInfoTable(item)
swapHeadersWithImages();
inner("shortInfo","<p style='border-bottom-width: 4px; border-bottom-style: solid; border-bottom-color: #222828; padding-top: 1.5rem; padding-bottom: 0.5rem;'>"+item.shortInfo + "</p><p style='margin-top: 2rem; margin-bottom: 1rem; text-align: center;'>" + '<a type="button" class="btn btn-outline-danger btn-sm" onclick="more()" style="--bs-btn-padding-x: .5rem; --bs-btn-color: #222828;">Tell me more...</a></p>');
inner("mediumInfo","<p style='border-bottom-width: 4px; border-bottom-style: solid; border-bottom-color: #222828; padding-top: 1.5rem; padding-bottom: 0.5rem;'>"+item.mediumInfo + "</p><p style='margin-top: 2rem; margin-bottom: 1rem; text-align: center;'>" + '<a type="button" class="btn btn-outline-danger btn-sm" onclick="less()" style="--bs-btn-padding-x: .5rem; --bs-btn-color: #222828;">Tell me less</a> or <a type="button" class="btn btn-outline-danger btn-sm" onclick="muchMore()" style="--bs-btn-padding-x: .5rem; --bs-btn-color: #222828;">Tell me even more...</a></p>');
byId("longInfo").dataset['uri'] = item.longInfo
currentValue = item.shortName
prepareNavigationButtons(index)
}
function more() {
hide("shortInfo") ;
show("mediumInfo") ;
hide("longInfo") ;
}
function less() {
hide("mediumInfo") ;
show("shortInfo") ;
hide("longInfo") ;
}
function muchMore() {
var uri = byId("longInfo").dataset['uri'];
fetch(uri)
.then(response => response.text())
.then(data => {
inner("longInfoContent",data) ;
hide("mainCard") ;
show("longInfo") ;
window.scrollTo(0,0)
})
}
function hideLongInfo() {
hide("mediumInfo") ;
show("shortInfo") ;
hide("longInfo") ;
show("mainCard") ;
}
function createInfoTable(item) {
inner("infoTable","",true) ;
for (i in item.info) {
if (item.info[i] !== null) {
if(i == "Invention date"){
var items = item.info[i].split(", ")
var val = []
for (j in items) {
val.push('<a class="button" role="button" href="#" onclick="changeNarrative(\''+"Timeline"+'\',\''+items[j]+'\')">'+items[j]+'</a>')
}
inner("infoTable","<tr><th>"+i+"</th><td>"+val.join(", ")+"</td></tr>", false)
}
else if (narratives.includes(item.info[i])) {
var items = item.info[i].split(", ")
var val = []
for (j in items) {
val.push('<a class="button" role="button" href="#" onclick="changeNarrative(\''+item.info[i]+'\',\''+items[j]+'\')">'+items[j]+'</a>')
}
inner("infoTable","<tr><th>"+i+"</th><td>"+val.join(", ")+"</td></tr>", false)
} else {
inner("infoTable","<tr><th>"+i+"</th><td>"+item.info[i]+"</td></tr>", false)
}
}
}
}
function prepareNavigationButtons(index) {
if (index > 0) {
byId("buttonPrevious").disabled = false
byId("buttonPrevious").onclick = () => showInfo(index-1)
byId("buttonPrevious").innerHTML = currentSelection[index-1].shortName
} else {
byId("buttonPrevious").disabled = true
byId("buttonPrevious").onclick = null
byId("buttonPrevious").innerHTML = "--"
}
if (index < currentSelection.length-1) {
byId("buttonNext").disabled = false
byId("buttonNext").onclick = () => showInfo(index+1)
byId("buttonNext").innerHTML = currentSelection[index+1].shortName
} else {
byId("buttonNext").disabled = true
byId("buttonNext").onclick = null
byId("buttonNext").innerHTML = "--"
}
inner('narrative', currentNarrative+": "+currentValue)
}
function changeNarrative(narrative,value) {
currentNarrative = narrative
currentValue = value
inner('narrative', currentNarrative+": "+currentValue)
prepareNarratives()
}
function byId(id) {
return document.getElementById(id)
}
function show(id) {
document.getElementById(id).classList.remove('d-none')
}
function hide(id) {
document.getElementById(id).classList.add('d-none')
}
function inner(id,content, emptyFirst=true) {
if(emptyFirst) document.getElementById(id).innerHTML = "" ;
document.getElementById(id).innerHTML += content ;
}
function swapHeadersWithImages() {
// Create an array of image URLs
const images = [
'img/icons/tag.png', // Replace with the actual URL for "Name"
'img/icons/calendar.png', // Replace with the actual URL for "Invention date"
'img/icons/location-pin.png', // Replace with the actual URL for "Invention place"
'img/icons/settings.png' // Replace with the actual URL for "Type of device"
];
// Get all the elements in the table
const headers = document.querySelectorAll('#infoTable th');
// Loop through each header and replace text with image
headers.forEach((header, index) => {
if (images[index]) {
const img = document.createElement('img');
img.src = images[index];
img.alt = header.innerText; // Set alt text for accessibility
header.innerHTML = ''; // Clear the existing text
header.appendChild(img); // Append the image
}
});
}