Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
56 lines (47 loc) · 1.76 KB
/
Copy pathscript.js
File metadata and controls
56 lines (47 loc) · 1.76 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
49
50
51
52
53
54
55
56
//"https://api.github.com/users/MC3D"
//"https://api.github.com/users/MC3D/repos"
//"https://api.github.com/users/jacobthemyth/starred"
//"https://api.github.com/users/jacobthemyth/orgs"
function renderTemplate(templateId, location, model) {
var templateString = $(templateId).text();
var templateFunction = _.template(templateString);
var renderedTemplate = templateFunction(model);
$(location).append(renderedTemplate);
}
$.getJSON("https://api.github.com/users/MC3D").done(function(item) {
var userData = {
avatar: item.avatar_url,
avatar_url: item.html_url,
username: item.login,
name: item.name,
memberSince: moment(item.created_at).format("MMM DD, YYYY"),
followers: item.followers,
following: item.following,
};
$.getJSON("https://api.github.com/users/MC3D/starred").done(function(item) {
userData.starred = item.length,
$.getJSON("https://api.github.com/users/MC3D/orgs").done(function(item) {
_.each(item, function(item) {
userData.org_avatar = item.avatar_url;
userData.org_name = item.login;
});
renderTemplate('#header-user', '#header-block', userData);
renderTemplate('#sidebar-user', '#sidebar', userData);
});
});
});
$.getJSON("https://api.github.com/users/MC3D/repos").done(function(item) {
var sortData = _.sortBy(item, 'updated_at').reverse();
_.each(sortData, function(item) {
var repoData = {
name: item.name,
updated: moment(item.updated_at).fromNow(),
language: item.language,
stargazers: item.stargazers_count,
forks: item.forks,
repoUrl: item.html_url,
fullName: item.full_name
};
renderTemplate('#repo-data', '#main-content', repoData);
});
});