Skip to content

Instantly share code, notes, and snippets.

@benaston
Forked from anonymous/youtube
Created October 17, 2012 17:25
Show Gist options
  • Save benaston/3906867 to your computer and use it in GitHub Desktop.
Save benaston/3906867 to your computer and use it in GitHub Desktop.
Shivas Code
(function( $ ){
$.fn.youtubeGallery = function( options ) {
var html = '';
var playListBaseURL = 'http://gdata.youtube.com/feeds/api/playlists/';
var videoBaseURL = 'http://www.youtube.com/watch?v=';
var youtubeBaseURL = 'http://www.youtube.com/';
var that = this;
settings = $.extend({
'height' : '450',
'width' : '300',
'totalVideo' : '15' ,
'user' : '',
'channel' : '',
'playlist' : '',
'allowfullscreen' : true
}, options);
function buildPlayListURL(){
return playListBaseURL + settings.playlist + '?v=2&alt=json&callback=?';
}
function buildChannelURL(){
return youtubeBaseURL + 'feeds/base/users' + settings.user + '/' + settings.channel + 'alt=json' ;
}
//TODO
function createPlayList(success){
$.getJSON(buildPlayListURL(), success)
.error(function() { console.log("oops"); });
}
function buildPlaylistHtml(playlistItems) {
var playList = '<ul>';
$.each(playlistItems, function(i, item) {
var feedTitle = item.title.$t;
var feedURL = item.link[1].href;
var fragments = feedURL.split("/");
var videoID = fragments[fragments.length - 2];
var url = videoBaseURL + videoID;
var thumb = "http://img.youtube.com/vi/"+ videoID +"/default.jpg";
playList += '<li><a href="'+ url +'" title="'+ feedTitle +'"><img alt="'+ feedTitle+'" src="'+ thumb +'"</a></li>';
});
playList += '</ul>';
return playList;
}
function appendToDom(html) {
that.append(html);
}
function createSlider(){}
function createPlayer(){}
function getPlayerHeight(){
return settings.height
}
function getPlayerWidth(){
return settings.width;
}
function getFullScreen(){
if(settings.allowfullscreen)
return ('allowfullscreen');
else
return '';
}
function embedYoutubePlayer(){
var embedsrc = videoBaseURL + 'embed' ;
var embedCode =
'<iframe src="' +
embedsrc + '" height="' +
getPlayerHeight() +
'" width="' + getPlayerWidth() +
'" ' + getFullScreen() +
'</iframe>';
return embedCode;
}
// createPlayList(function() { addSlider(); appendToDom(); });
function main(){
createplaylist(function(data) {
var html = buildPlaylistHtml(data.feed.entry);
html = addSlider(html);
html = createPlayer(html);
appendToDom(html);
});
}
main();
return this;
};
})( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment