|
1 | 1 | (function ($) { |
2 | 2 | function addRecentlyUpdatedRepo(repo) { |
3 | 3 | var $item = $("<li>"); |
4 | | - |
5 | 4 | $item.append('<span class="name"><a href="' + repo.html_url + '">' + repo.name + '</a></span>'); |
6 | 5 | $item.append('<span class="time"><a href="' + repo.html_url + '/commits">' + strftime("%h %e, %Y", repo.pushed_at) + '</a></span>'); |
7 | 6 | $item.append('<span class="bullet">⋅</span>'); |
8 | 7 | $item.append('<span class="watchers"><a href="' + repo.html_url + '/watchers">' + repo.watchers + ' watchers</a></span>'); |
9 | 8 | $item.append('<span class="bullet">⋅</span>'); |
10 | 9 | $item.append('<span class="forks"><a href="' + repo.html_url + '/network">' + repo.forks + ' forks</a></span>'); |
11 | | - |
12 | 10 | $item.appendTo("#recently-updated-repos"); |
13 | 11 | } |
14 | 12 |
|
15 | 13 | function addProject(project) { |
16 | | - var $project = $("<div />").addClass("project"); |
| 14 | + var $project = $("<div>").addClass("project"); |
17 | 15 | $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)); |
| 16 | + $project.append($("<h2>").text(project.name)); |
| 17 | + $project.append($("<h3>").text(project.language)); |
| 18 | + $project.append($("<p>").text(project.description)); |
21 | 19 | $project.appendTo("#projects"); |
22 | 20 | } |
23 | 21 |
|
|
32 | 30 | repo.pushed_at = new Date(repo.pushed_at); |
33 | 31 | }); |
34 | 32 |
|
35 | | - // Sort by most-recently pushed to. |
| 33 | + // Sort by most # of watchers. |
36 | 34 | repos.sort(function (a, b) { |
37 | | - if (a.pushed_at < b.pushed_at) return 1; |
38 | | - if (b.pushed_at < a.pushed_at) return -1; |
| 35 | + if (a.watchers < b.watchers) return 1; |
| 36 | + if (b.watchers < a.watchers) return -1; |
39 | 37 | return 0; |
40 | 38 | }); |
41 | 39 |
|
42 | | - $.each(repos, function(i, repo){ |
| 40 | + $.each(repos, function (i, repo) { |
43 | 41 | addProject(repo); |
44 | 42 | }); |
45 | 43 |
|
| 44 | + // Sort by most-recently pushed to. |
| 45 | + repos.sort(function (a, b) { |
| 46 | + if (a.pushed_at < b.pushed_at) return 1; |
| 47 | + if (b.pushed_at < a.pushed_at) return -1; |
| 48 | + return 0; |
| 49 | + }); |
| 50 | + |
46 | 51 | $.each(repos.slice(0, 3), function (i, repo) { |
47 | 52 | addRecentlyUpdatedRepo(repo); |
48 | 53 | }); |
|
0 commit comments