Skip to content

Commit 1fc3512

Browse files
committed
refactor
1 parent ab5ec4a commit 1fc3512

File tree

2 files changed

+63
-46
lines changed

2 files changed

+63
-46
lines changed

assets/application.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
(function($){
2+
function addRecentlyUpdatedRepo(repo) {
3+
var $item = $("<li>");
4+
5+
$item.append('<span class="name"><a href="' + repo.html_url + '">' + repo.name + '</a></span>');
6+
$item.append('<span class="time">' + strftime("%h %e, %Y", repo.pushed_at) + '</span>');
7+
$item.append('<span class="bullet">&sdot;</span>');
8+
$item.append('<span class="watchers">' + repo.watchers + ' watchers</span>');
9+
$item.append('<span class="bullet">&sdot;</span>');
10+
$item.append('<span class="forks">' + repo.forks + ' forks</span>');
11+
12+
$item.appendTo("#recently-updated-repos");
13+
}
14+
15+
function addProject(project) {
16+
var $project = $("<div />").addClass("project");
17+
$project.addClass(project.language);
18+
$project.append($("<h2 />").text(project.name));
19+
$project.append($("<h3 />").text(project.language));
20+
$project.append($("<p />").text(project.description));
21+
$project.appendTo("#projects");
22+
}
23+
24+
$.getJSON("https://api.github.com/users/twitter/repos?callback=?", function (result) {
25+
var repos = result.data;
26+
27+
$(function () {
28+
$("#num-repos").val(repos.length);
29+
30+
$.each(repos, function (i, repo) {
31+
repo.pushed_at = new Date(repo.pushed_at);
32+
});
33+
34+
// Sort by most-recently pushed to.
35+
repos.sort(function (a, b) {
36+
if (a.pushed_at < b.pushed_at) return 1;
37+
if (b.pushed_at < a.pushed_at) return -1;
38+
return 0;
39+
});
40+
41+
$.each(repos, function(i, repo){
42+
addProject(repo);
43+
});
44+
45+
$.each(repos.slice(0, 3), function (i, repo) {
46+
addRecentlyUpdatedRepo(repo);
47+
});
48+
});
49+
});
50+
51+
$.getJSON("https://api.github.com/orgs/twitter/members?callback=?", function (members) {
52+
$(function () {
53+
$("#num-members").val(members.length);
54+
});
55+
});
56+
})(jQuery);

index.html

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,61 +8,19 @@
88
<link rel="stylesheet" type="text/css" href="assets/style.css">
99
<script type="text/javascript" src="assets/jquery-1.7.1.min.js"></script>
1010
<script type="text/javascript" src="assets/strftime.js"></script>
11-
<script type="text/javascript">
12-
function addRecentlyUpdatedRepo(repo) {
13-
var $item = $("<li>");
14-
$item.append('<span class="name"><a href="' + repo.html_url + '">' + repo.name + '</a></span>');
15-
$item.append('<span class="time">' + strftime("%h %e, %Y", repo.pushed_at) + '</span>');
16-
$item.append('<span class="bullet">&sdot;</span>');
17-
$item.append('<span class="watchers">' + repo.watchers + ' watchers</span>');
18-
$item.append('<span class="bullet">&sdot;</span>');
19-
$item.append('<span class="forks">' + repo.forks + ' forks</span>');
20-
$item.appendTo("#recently-updated-repos");
21-
}
22-
23-
$.getJSON("https://api.github.com/users/twitter/repos", function (repos) {
24-
$(function () {
25-
$("#num-repos").val(repos.length);
26-
27-
$.each(repos, function (i, repo) {
28-
repo.pushed_at = new Date(repo.pushed_at);
29-
});
30-
31-
// Sort by most-recently pushed to.
32-
repos.sort(function (a, b) {
33-
if (a.pushed_at < b.pushed_at) return 1;
34-
if (b.pushed_at < a.pushed_at) return -1;
35-
return 0;
36-
});
37-
38-
$.each(repos.slice(0, 3), function (i, repo) {
39-
addRecentlyUpdatedRepo(repo);
40-
});
41-
});
42-
});
43-
44-
// $.getJSON("https://api.github.com/orgs/twitter", function (data) {
45-
// $(function () {
46-
// $("#num-repos").val(data.public_repos);
47-
// });
48-
// });
49-
50-
$.getJSON("https://api.github.com/orgs/twitter/members", function (members) {
51-
$(function () {
52-
$("#num-members").val(members.length);
53-
});
54-
});
55-
</script>
11+
<script type="text/javascript" src="assets/application.js"></script>
5612
</head>
5713
<body>
5814
<div id="wrapper" class="grid clearfix">
15+
5916
<div id="main" class="grid-1">
6017
<div id="logo"><h1>Twitter Open Source</h1></div>
6118
<h1>Twitter is built on open source software.</h1>
6219
<p>Want to help? <a href="#">Join the Flock</a></p>
6320
<p>Visit <a href="#">dev.twitter.com</a></p>
6421
<p><a href="#">Logos and other goodies</a></p>
6522
</div>
23+
6624
<div class="grid grid-3">
6725
<div id="statistics" class="grid-1 alpha header">
6826
<h1>Statistics</h1>
@@ -75,11 +33,14 @@ <h1>Statistics</h1>
7533
</p>
7634
<p><a href="mailto:[email protected]">[email protected]</a></p>
7735
</div>
36+
7837
<div id="recently-updated" class="grid-2 omega header">
7938
<h1>Recently updated</h1>
8039
<ol id="recently-updated-repos"></ol>
8140
</div>
8241
</div>
42+
43+
<div id="projects"></div>
8344
</div>
8445
</body>
85-
</html>
46+
</html>

0 commit comments

Comments
 (0)