-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
54 lines (44 loc) · 1.83 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
49
50
51
52
53
54
const app = document.getElementById('root');
const container = document.createElement('div');
container.setAttribute('class', 'container');
app.appendChild(container);
const main_title = document.createElement('h1');
main_title.textContent = "Contributors Index";
main_title.setAttribute = ('id', 'main-title');
main_title.setAttribute = ('class', 'hvr-underline-from-center');
container.appendChild(main_title);
var request = new XMLHttpRequest();
request.open('GET', 'api.json', true);
request.onload = function () {
var data = JSON.parse(this.response);
if (request.status >= 200 && request.status < 404) {
data.forEach(contri => {
const card = document.createElement('div');
card.setAttribute('class', 'card');
const card_body = document.createElement('div');
card_body.setAttribute = ('class', 'card-body');
const name = document.createElement('h1');
name.setAttribute = ('class', 'card-title');
name.textContent = contri.name;
const bio = document.createElement('p');
bio.setAttribute = ('class', 'card-text');
bio.textContent = contri.bio;
const anchor = document.createElement('a');
anchor.textContent = contri.github_username;
anchor.href = contri.github_url;
anchor.target = "_blank";
anchor.setAttribute = ('class', 'btn btn-dark');
/*anchor.addEventListener("click", function() {
window.open(contri.github_url);
});*/
container.appendChild(card);
card.appendChild(card_body);
card_body.appendChild(name);
card_body.appendChild(bio);
card_body.appendChild(anchor);
});
} else {
console.log("Bad Request");
}
};
request.send();