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
var GitHubRepos = new function(){ | |
this.displayObjects = new Array(); | |
//retrieve the repo information from github | |
this.GetRepos = function() | |
{ | |
//... | |
} | |
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
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 |
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
//... | |
//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) | |
{ |
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
<script src='http://github.com/api/v1/json/johnbender&callback=GitHubRepos.DisplayRepos' | |
type='text/javascript' > | |
</script> |
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
//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]) |
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
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>"; |
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
<div class="github-projects" id="johnbender" style="display: block;"> | |
<div class="github-projects-title">GitHub Projects</div> | |
</div> |
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
//... | |
//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 |
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
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"}}); |