Forked from lsloan/ List GitHub Projects Using jQuery
Last active
December 13, 2016 22:38
-
-
Save Nicola1971/8d9194e0cb40998606a2b545d2908eb3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://aboutcode.net/2010/11/11/list-github-projects-using-javascript.html | |
jQuery.githubUserRepositories = function(username, callback) { | |
jQuery.getJSON("https://api.github.com/users/" + username + "/repos?callback=?", callback); | |
} | |
jQuery.fn.loadRepositories = function(username) { | |
this.html("<span>Querying GitHub for repositories...</span>"); | |
var target = this; | |
$.githubUserRepositories(username, function(data) { | |
var repos = data.data; | |
sortByNumberOfWatchers(repos); | |
var list = $('<dl/>'); | |
target.empty().append(list); | |
$(repos).each(function() { | |
list.append('<dt><a href="'+ this.url +'">' + this.name + '</a></dt>'); | |
list.append('<dd>' + this.description + '</dd>'); | |
}); | |
}); | |
function sortByNumberOfWatchers(repos) { | |
repos.sort(function(a,b) { | |
return b.watchers - a.watchers; | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment