Skip to content

Instantly share code, notes, and snippets.

View johnbender's full-sized avatar

John Bender johnbender

View GitHub Profile
var GitHubRepos = new function(){
this.displayObjects = new Array();
//retrieve the repo information from github
this.GetRepos = function()
{
//...
}
this.GetRepos = function()
{
//create an array of the github data, used to prevent mutiple hits
//to the server for the same user
var github_usernames = new Array();
//for all the github-projects divs
$(GITHUB_PROJECTS_CLASS).each(function(i) {
//create an array of all unique userids in the page
//...
//create an array of all unique userids in the page
if(this.id != undefined)
{
var username = this.id;
//add this object (div by default) that met the query parameters
//to a list to be altered later
if( GitHubRepos.displayObjects[username] == undefined)
{
<script src='http://github.com/api/v1/json/johnbender&callback=GitHubRepos.DisplayRepos'
type='text/javascript' >
</script>
//add the repo data to the div using the template
this.DisplayRepos = function(data)
{
//if we got properly formed data
if(data.user != undefined)
{
var user = data.user;
//for all the div objects that correspond to that user
for(var j in GitHubRepos.displayObjects[user.login])
GITHUB_JSON_URL = "http://github.com/api/v1/json/{0}?callback={1}";
DYNAMIC_SCRIPT_TEMPLATE = "<script src='{0}' type='text/javascript' ></script>";
GITHUB_PROJECTS_CLASS = ".github-projects";
REPO_TEMPLATE =
"<div class='github-repo'>"
+ "<a href='{0}' target='_blank'>"
+ "{1}<img class='github-repo-link-image'"
+ "src='http://erlanguid.com/icons/external.png'"
+ "</a>"
+"</div>";
<div class="github-projects" id="johnbender" style="display: block;">
<div class="github-projects-title">GitHub Projects</div>
</div>
//...
//for each unique user
for(var i in GitHubRepos.displayObjects)
{
//format the github url for our given user and callback function
var github_url = format(GITHUB_JSON_URL, i, "GitHubRepos.DisplayRepos");
//insert a script into the DOM to add our JSON data via the github url
//once the script loads it will callback the DATA_DISPLAY_FUCNTION
GitHubRepos.DisplayRepos({"user": {"name": "John Bender", "repositories": [{"owner": "johnbender", "description": "Unit testing with Ruby for simple C bits, or small pieces of larger projects.", "name": "ryc", "watchers": 1, "private": false, "url": "http://github.com/johnbender/ryc", "forks": 0, "fork": false, "homepage": ""}, {"owner": "johnbender", "description": "GitHub Blog Badges for Everyone", "name": "github-badges", "watchers": 1, "private": false, "url": "http://github.com/johnbender/github-badges", "forks": 0, "fork": true, "homepage": "http://drnicjavascript.rubyforge.org/github_badge/"}], "blog": "http://nickelcode.com", "login": "johnbender", "location": "New York, NY"}});
<div class="delicious-user-top-links" id="johndoe|erlang+mnesia">
</div>