-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathapp.js
More file actions
148 lines (138 loc) · 6.53 KB
/
app.js
File metadata and controls
148 lines (138 loc) · 6.53 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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
"use strict";
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
(function ($, undefined) {
var orgName = 'h5bp';
var stars = 0;
// Return the repo url
function getRepoUrl(repo) {
return repo.homepage || repo.html_url;
}
// Return the repo description
function getRepoDesc(repo) {
return repo.description;
}
// Display a repo's overview (for recent updates section)
function showRepoOverview(repo) {
var item = "\n <li>\n <span class=\"name\"><a href=\"".concat(repo.html_url, "\">").concat(repo.name, "</a></span>\n ·\n <span class=\"time\"><a href=\"").concat(repo.html_url, "/commits\">").concat(html5prettyDate(repo.pushed_at), "</a></span>\n </li>");
$(item).appendTo("#updated-repos");
}
// Create an entry for the repo in the grid of org repos
function showRepo(repo) {
var url = getRepoUrl(repo);
var language = repo.language !== null ? "·".concat(repo.language) : '';
// Create links for GitHub repo and homepage
var githubLink = "<a href=\"".concat(repo.html_url, "\" class=\"repo__link repo__link--github\" title=\"View source code\">GitHub</a>");
var homepageLink = repo.homepage ? "<a href=\"".concat(repo.homepage, "\" class=\"repo__link repo__link--homepage\" title=\"Visit project homepage\">Homepage</a>") : '';
var linksHtml = "<div class=\"repo__links\">".concat(githubLink).concat(homepageLink, "</div>");
var $item = $("<div class=\"unit-1-3 repo=\">\n <div class=\"box\">\n <h2 class=\"repo__name\">".concat(repo.name, "</h2>\n <p class=\"repo__info\">").concat(repo.watchers, " stargazers ").concat(language, "</p>\n <p class=\"repo__desc\">").concat(getRepoDesc(repo), "</p>\n ").concat(linksHtml, "\n </div>\n </div>"));
$item.on("click", function (e) {
// Don't navigate if clicking on a link
if (!$(e.target).hasClass('repo__link')) {
window.location = url;
}
});
$item.appendTo('#repos');
}
$.getJSON("https://api.github.com/orgs/".concat(orgName, "/repos?callback=?"), function (result) {
var repos = result.data;
$('#num-repos').text(repos.length);
var _iterator = _createForOfIteratorHelper(repos),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var repo = _step.value;
repo.pushed_at = new Date(repo.pushed_at);
var weekHalfLife = 1.146 * Math.pow(10, -9);
var pushDelta = new Date() - Date.parse(repo.pushed_at);
var createdDelta = new Date() - Date.parse(repo.created_at);
var weightForPush = 1;
var weightForWatchers = 1.314 * Math.pow(10, 7);
repo.hotness = weightForPush * Math.pow(Math.E, -1 * weekHalfLife * pushDelta);
repo.hotness += weightForWatchers * repo.watchers / createdDelta;
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
repos.sort(function (a, b) {
if (a.hotness < b.hotness) return 1;
if (b.hotness < a.hotness) return -1;
return 0;
});
var _iterator2 = _createForOfIteratorHelper(repos),
_step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var _repo = _step2.value;
stars += _repo.stargazers_count;
if (_repo.archived === false) {
showRepo(_repo);
}
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
$("#num-stargazers").text(stars.toLocaleString());
// Sort by most-recently pushed to.
repos.sort(function (a, b) {
if (a.pushed_at < b.pushed_at) {
return 1;
} else if (b.pushed_at < a.pushed_at) {
return -1;
} else {
return 0;
}
});
$.each(repos.slice(0, 3), function (i, repo) {
showRepoOverview(repo);
});
});
$.getJSON("https://api.github.com/orgs/".concat(orgName, "/members?per_page=100&callback=?"), function (result) {
var members = result.data;
$(function () {
$('#num-members').text(members.length);
});
});
// Relative times
function prettyDate(rawdate) {
var date,
seconds,
formats,
i = 0,
f;
date = new Date(rawdate);
seconds = (new Date() - date) / 1000;
formats = [[60, 'seconds', 1], [120, '1 minute ago'], [3600, 'minutes', 60], [7200, '1 hour ago'], [86400, 'hours', 3600], [172800, 'Yesterday'], [604800, 'days', 86400], [1209600, '1 week ago'], [2678400, 'weeks', 604800]];
while (f = formats[i++]) {
if (seconds < f[0]) {
return f[2] ? Math.floor(seconds / f[2]) + ' ' + f[1] + ' ago' : f[1];
}
}
return 'A while ago';
}
// Wraps prettyDate in an HTML5 <time> element
function html5prettyDate(rawdate) {
return '<time datetime="' + rawdate.toISOString() + '">' + prettyDate(rawdate) + '</time>';
}
})(jQuery);
// External 3rd party scripts
(function (doc, script) {
var js,
fjs = doc.getElementsByTagName(script)[0],
add = function add(url, id) {
if (doc.getElementById(id)) {
return;
}
js = doc.createElement(script);
js.src = url;
id && (js.id = id);
fjs.parentNode.insertBefore(js, fjs);
};
// Twitter SDK
add('https://platform.twitter.com/widgets.js', 'twitter-wjs');
})(document, 'script');