forked from willwhite/longneck
-
Notifications
You must be signed in to change notification settings - Fork 1
/
site.js
84 lines (74 loc) · 2.73 KB
/
site.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
---
---
;{% include js/jquery-1.6.4.min.js %}
;{% include js/underscore.js %}
;
(function(context) {
var longneck = {};
longneck.githubWatcherProject = function(resp) {
var watcherProject = $('.follower-project');
var i = 0;
var max = 4; // Make a maximum of five requests before giving up.
var shuffled = _(resp.data).shuffle();
var getProjects = function(u) {
$.ajax({
url: 'https://api.github.com/users/' + u.login + '/repos',
dataType: 'jsonp',
success: function(resp) {
if (!resp.data.length) return;
var repo = _(resp.data)
.chain()
.shuffle()
.detect(function(r) { return r.language === '{{site.github_lanaguage}}' })
.value();
if (!repo) {
getProjects(shuffled[i++]);
} else {
var template =
""
+ "<a target='_blank' href='http://github.com/<%=owner.login%>'><%=owner.login%></a>"
+ " / "
+ "<a target='_blank' href='<%=html_url%>'>"
+ "<span class='title'><strong><%=name%></strong></span>"
+ "</a>"
+ "<span class='title'> <%=description%></span>"
+ "";
var t = _(template).template(repo);
watcherProject.append(t).addClass('loaded');
}
}
});
};
getProjects(shuffled[i]);
};
longneck.githubWatchers = function() {
var watchers = $('.followers');
$.ajax({
// TODO: this endpoint only returns maximum 30 users. Implement random
// pagination so we see different groups of people.
url: 'https://api.github.com/repos/{{site.github_login}}/{{site.github_repo}}/subscribers',
dataType: 'jsonp',
success: function(resp) {
if (!resp.data.length) return;
longneck.githubWatcherProject(resp);
var template =
"<a class='github-user' target='_blank' href='http://github.com/<%=login%>'>"
+ "<span style='background-image:url(<%=avatar_url%>)' class='thumb' /></span>"
+ "</a>";
var t = _(resp.data)
.map(function(i) { return _(template).template(i); })
.join('');
watchers.append(t);
}
});
};
$(longneck.githubWatchers);
longneck.setup = function() {
$('.watch').hover(
function() { $('.watch-docs').addClass('active') },
function() { $('.watch-docs').removeClass('active') }
)
}
$(longneck.setup);
context.longneck = longneck;
})(window);