-
-
Save lsloan/b600906631c913f575d1 to your computer and use it in GitHub Desktop.
An example JavaScript program using jQuery to get a list of GitHub projects.
This file contains hidden or 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
Gist title: "List GitHub Projects Using jQuery" | |
Summary: An example JavaScript program using jQuery to get a list of GitHub projects. | |
Original source: http://aboutcode.net/2010/11/11/list-github-projects-using-javascript.html |
This file contains hidden or 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.loadRepositores = 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
I changed the GH API URL and which attribute of the returned data is used. The change of URL actually changes the nature of the githubUser function into a "githubUserRepositories" one. If we wanted the githubUser function to continue to return data about the user, another method could be added that would do the repo query based on it.