Skip to content

Instantly share code, notes, and snippets.

@hugodias
Created November 7, 2012 12:14
Show Gist options
  • Save hugodias/4031128 to your computer and use it in GitHub Desktop.
Save hugodias/4031128 to your computer and use it in GitHub Desktop.
Load multiple videos from youtube using JSON
<script type="text/javascript">
function loadVideoInfo(ID) {
var i = 1;
return $.getJSON('http://gdata.youtube.com/feeds/api/videos/'+ID+'?v=2&alt=jsonc',function(data,status,xhr){
var template,thumbnail,nome,ul;
thumbnail = data.data.thumbnail.hqDefault;
nome = data.data.title;
if( i%5 === 0 ) {
ul = '</ul><ul class="thumbnails">';
} else {
ul = '';
}
template = {
thumb: thumbnail,
nome: nome,
ul: ul
}
$('#videosTemplate').tmpl(template).appendTo('.thumbnails');
i++;
});
}
$(function(){
$.each(videos,function(key,value){
// Video ID
loadVideoInfo(value);
})
});
</script>
<script id="videosTemplate" type="text/html">
${ul}
<li class="span3">
<div class="thumbnail">
<img src="${thumb}" title="${nome}">
<div class="caption" style="text-align:center;">
<button class="btn btn-danger">Remover</button>
</div>
</div>
</li>
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment