forked from revspace/hackeropuit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid.js
57 lines (50 loc) · 1.33 KB
/
grid.js
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
function getJSON(url) {
var resp;
var xmlHttp;
resp = '';
xmlHttp = new XMLHttpRequest();
if (xmlHttp != null) {
xmlHttp.open("GET", url, false);
xmlHttp.send(null);
resp = xmlHttp.responseText;
}
return resp;
}
//var jsondata = getJSON('https://hackeropuit.nl/events.json');
var jsondata = getJSON('events.json');
var columns = ["Name", "Location", "StartDate", "EndDate", "Comment", "URL"]
// (B) PARSE JSON INTO OBJECT
var parsed = JSON.parse(jsondata);
console.table(parsed);
// (C) TABLE HEADER
var theWrap = document.getElementById("tableWrap");
var theCell = null;
for (let key in columns) {
theCell = document.createElement("div");
theCell.innerHTML = columns[key];
theCell.classList.add("cell");
theCell.classList.add("head");
theWrap.appendChild(theCell);
}
// (D) TABLE CELLS
var theEvent = null;
var altRow = false;
for (let key in parsed) {
theEvent = parsed[key];
for (let i in theEvent) {
theCell = document.createElement("div");
if (i == "URL") {
if (theEvent[i] != null) {
theCell.innerHTML = "<A HREF='" theEvent[i] "'>" theEvent[i] "</A>";
}
} else {
theCell.innerHTML = theEvent[i];
}
theCell.classList.add("cell");
if (altRow) {
theCell.classList.add("alt");
}
theWrap.appendChild(theCell);
}
altRow = !altRow;
}