Skip to content

Instantly share code, notes, and snippets.

@anarchivist
Created December 24, 2009 20:34
Show Gist options
  • Select an option

  • Save anarchivist/263362 to your computer and use it in GitHub Desktop.

Select an option

Save anarchivist/263362 to your computer and use it in GitHub Desktop.
Add a list of recent Gists to any page using jQuery
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Gist/jQuery Demo</title>
<script src="http://www.google.com/jsapi"></script>
<script>
var ghusername = 'anarchivist';
function getgists(githubuser) {
$.getJSON("http://gist.github.com/api/v1/json/gists/" +githubuser+ "?callback=?", function(data) {
var gisthtml = '';
for (var i = 0; i < 10;) {
var item = data.gists[i];
if (item.public) {
i++;
var desc = item.description;
if (desc === null) {
desc = '(no description)';
}
else {if (desc.length > 50) {
desc = desc.substring(0, 40).replace(/w+$/, '') + '&#133;';
}}
gisthtml += '<li class="gist"><a href="http://gist.github.com/' + item.repo + '"><span class="gist-id">#' + item.repo + ': </span>' + desc + '</a></p>';
}
};
if (data.gists.length > 10) {gisthtml += '<li class="gist gist-more"><a href="http://gist.github.com/' + githubuser + '">More snippets&#133;</a>'};
$("#gists").html('<ul class="gist-list">'+gisthtml+'</ul>');
});
}
// Load jQuery
google.load("jquery", "1");
// on page load complete, load gists
google.setOnLoadCallback(function(){getgists(ghusername)});
</script>
</head>
<body>
<h1>Gist/jQuery Demo</h1>
<div id="gists"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment