-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
48 lines (43 loc) · 1.33 KB
/
script.js
File metadata and controls
48 lines (43 loc) · 1.33 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
Handlebars.templates = Handlebars.templates || {};
var templates = document.querySelectorAll(
'script[type="text/x-handlebars-template"]'
);
Array.prototype.slice.call(templates).forEach(function(script) {
Handlebars.templates[script.id] = Handlebars.compile(script.innerHTML);
});
const username = $(".username");
const password = $(".password");
const gitusername = $(".gitusername");
const repositories = $(".results");
$(".button").on("click", () => {
$.ajax({
url: `https://api.github.com/users/${gitusername.val()}/repos`,
headers: {
Authorization:
"Basic " + btoa(username.val() + ":" + password.val())
},
success: data => {
repositories.html(
Handlebars.templates.repositories({ repositories: data })
);
}
});
});
repositories.on("click", ".fullname", e => {
const reponame = $(e.target).text();
$.ajax({
url: `https://api.github.com/repos/${reponame}/commits`,
data: {
per_page: 10
},
headers: {
Authorization:
"Basic " + btoa(username.val() + ":" + password.val())
},
success: data => {
$(e.target)
.next()
.html(Handlebars.templates.commits({ commits: data }));
}
});
});