Created
September 2, 2015 18:10
-
-
Save esironal/0f4001369b321c368ed5 to your computer and use it in GitHub Desktop.
List Public Gists
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
var $List = $('#list'), | |
sUser ='potherca', | |
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); | |
}); | |
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