-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathcards.js
More file actions
33 lines (27 loc) · 1.39 KB
/
cards.js
File metadata and controls
33 lines (27 loc) · 1.39 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
// Cache will time out after 1 hour
var userCardCacheTimeMillis = 60 * 60 * 1000;
$(document).ready(function () {
$('div[data-card-user]').each(function (i, element) {
var $cardDiv = $(element);
getApiValue('https://api.github.com/users/' + $cardDiv.data('card-user'), userCardCacheTimeMillis, function (userData, error) {
if (error || !userData) {
console.error("User card data not available! Using static text card instead.");
return;
}
$cardDiv.empty();
$cardDiv = $('<a href="' + userData.html_url + '"></a>').appendTo($cardDiv);
var $avatarDiv = $('<div class="user-card-avatar"><img src="' + userData.avatar_url + '"/></div>').appendTo($cardDiv);
var $textDiv = $('<div class="user-card-text"></div>').appendTo($cardDiv);
$textDiv.append('<div class="user-card-name">' + (userData.name || userData.login) + '</div>');
$textDiv.append('<div class="user-card-login">@' + userData.login + '</div>');
// Give the text a margin to make sure it does not overlap the avatar
$avatarDiv.resize(function () {
$textDiv.css({
width: 'auto',
"margin-left": $avatarDiv.height()
});
});
$avatarDiv.resize();
});
});
});