Skip to content

Instantly share code, notes, and snippets.

@omero
Created October 20, 2015 22:21
Show Gist options
  • Save omero/115bad1b0cdc22a5b2bf to your computer and use it in GitHub Desktop.
Save omero/115bad1b0cdc22a5b2bf to your computer and use it in GitHub Desktop.
Contributors
$(document).ready(function() {
gitHubContributors();
});
function gitHubContributors() {
var
howMany = 70,
baseUrl = 'https://api.github.com/repos/hechoendrupal/DrupalConsole/contributors?per_page=' + howMany + '&callback=?',
$contributorsOutput = $("#contributors-list"),
$pager = $(".pager");
function _listContributors(data) {
$contributorsOutput.html("");
var html = '';
$(data).each(function(i, user) {
html += '<li><a href="' + user.url.replace('api.', '').replace('users/', '') + '"><img src="' + user.avatar_url + '" alt="' + user.login + '" class="contributor-avatar"></a></li>';
});
$contributorsOutput.html(html);
}
function _getContributors(apiUrl) {
$.ajax({
type: 'GET',
url: apiUrl,
async: true,
crossDomain: true,
contentType: "application/json",
dataType: 'jsonp',
success: function(data) {
if (data.meta.status != "200") {
_throwError(data.meta);
} else {
_listContributors(data.data); // output contribs
}
},
error: function(e) {
console.log(e.message);
}
});
}
function _throwError(data) {
$contributorsOutput.text("Error");
console.log(data);
}
_getContributors(baseUrl);
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript" src="github.js"></script>
</head>
<body>
<ul id="contributors-list"></ul>
</body>
</html>
#contributors-list li {
list-style-type: none;
display: inline-block;
margin-bottom: 0.5em;
margin-right: 0.5em;
width: 3.5em;
overflow: hidden;
}
#contributors-list li img {
max-width: 100%;
height: auto;
vertical-align: middle;
border: 0px none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment