/
index.js
48 lines (41 loc) · 1.58 KB
/
index.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
// const githubUsersApiEndPoint = 'https://api.github.com/users'
const githubEndPoint = 'https://github.com';
const addCollaborator = (collaborator) => {
const list = document.querySelector('.list');
const collaboratorEl = document.createElement('div');
collaboratorEl.className = 'collaborator';
const photo = document.createElement('img');
const name = document.createElement('b');
const role = document.createElement('span');
collaboratorEl.appendChild(photo);
collaboratorEl.appendChild(name);
collaboratorEl.appendChild(role);
photo.src = collaborator.photo_url;
name.innerHTML = collaborator.name;
role.innerHTML = collaborator.role;
list.appendChild(collaboratorEl);
if (collaborator.github_username) {
const githubLink = document.createElement('a');
const githubIcon = document.createElement('img');
githubIcon.src = './assets/imgs/github.svg';
githubLink.appendChild(githubIcon);
githubLink.href = `${githubEndPoint}/${collaborator.github_username}`;
githubLink.classList.add('contribIconLink');
collaboratorEl.insertAdjacentElement('beforeend', githubLink);
}
};
function readJsonFile(file, callback) {
var rawFile = new XMLHttpRequest();
rawFile.overrideMimeType('application/json');
rawFile.open('GET', file, true);
rawFile.onreadystatechange = function () {
if (rawFile.readyState === 4 && rawFile.status == '200') {
callback(rawFile.responseText);
}
};
rawFile.send(null);
}
readJsonFile('collaborators.json', function (text) {
collaborators = JSON.parse(text);
collaborators.forEach(addCollaborator);
});