Forked from lsloan/ List GitHub Projects Using jQuery
Last active
May 25, 2019 10:39
-
-
Save esironal/235d7797d881da11b0bc to your computer and use it in GitHub Desktop.
list-github-projects-using-javascript
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