Skip to content

Instantly share code, notes, and snippets.

@vereperrot
Last active November 27, 2015 10:32
Show Gist options
  • Save vereperrot/6b6bc1dc8e99051ceb78 to your computer and use it in GitHub Desktop.
Save vereperrot/6b6bc1dc8e99051ceb78 to your computer and use it in GitHub Desktop.
<h1>My Gists</h1>
<ul id="list"></ul>
var $List = $('#list'),
sUser ='perrot',
sUrl = 'https://api.github.com/users/' + sUser + '/gists'
;
$.ajax({
dataType: "json",
url: sUrl,
success: function(p_oData){
$.each(p_oData, function(p_iIndex, p_oRepo){
var bBlocksOrg, bDabblet, aLanguages = [], aFiles = [], sDescription;
$.each(p_oRepo.files, function(p_sFile, p_oFile){
/* the dabblet.css file is always the first in the gist */
if(typeof bDabblet === 'undefined'){
bDabblet = (p_sFile === 'dabblet.css')
}
/* we have no way of knowing the position of the index.html file so we need to check all files */
if(bBlocksOrg !== true){
bBlocksOrg = (p_sFile === 'index.html')
}
if(typeof aLanguages[p_oFile.language] === 'undefined'){
aLanguages.push(p_oFile.language);
}
aFiles.push(p_sFile);
});
console.log(p_oRepo);
sDescription = '<strong>' + aLanguages.join('/') + '</strong>: ' + aFiles.join(', ');
$List.append(
'<li>'
+ ' <a href="' + p_oRepo.html_url + '" class="icon icon-github" target="_blank"> '
+ (p_oRepo.description?p_oRepo.description:'-- no description --') + '</a>'
+ (bDabblet?'<a href="http://dabblet.com/gist/' + p_oRepo.id + '" title="Open on Dabblet" target="_blank"><img src="http://dabblet.com/favicon.png" /></a>':'')
+ (bBlocksOrg?'<a href="http://bl.ocks.org/' + sUser + '/' + p_oRepo.id + '" title="Open on bl.ocks.org" target="_blank"><img src="http://bl.ocks.org/favicon.png" /></a>':'')
+ '<span class="description">' + sDescription + '</span>'
+ '</li>'
);
});
},
error: function(p_oJqXHR, p_sStatus, p_sError){
$List.append('<li class="error">' + p_sError + ': ' + p_sStatus + '</li>');
}
});
/*EOF*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment