-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
33 lines (29 loc) · 946 Bytes
/
main.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
function assignColors(fields) {
for(var i=0; i!=fields.length; i++) {
var a = document.getElementById(fields[i].toLowerCase().replace(" ", ""));
var color = 360*i/fields.length;
color="hsl(" + color + ",60%, 50%)";
a.style.backgroundColor = color;
}
}
function loadFile(filename, mimetype, cbk) {
var xhr = new XMLHttpRequest();
xhr.overrideMimeType(mimetype);
xhr.open('GET', filename, true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == "200") {
cbk(xhr.responseText);
}
}
xhr.send(null);
}
function loadPartial(templatePath, dataPath, insertionElement, customCallback) {
loadFile(dataPath,"application/json", function(response) {
var jsonresponse = JSON.parse(response);
var text = new EJS({url: templatePath}).render(jsonresponse);
insertionElement.innerHTML += text;
if(customCallback) {
customCallback(jsonresponse);
}
});
}