Created
October 17, 2012 17:15
-
-
Save anonymous/3906808 to your computer and use it in GitHub Desktop.
Shivas Code
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
(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(done){ | |
$.getJSON(buildPlayListURL(), function(data) { | |
var playList = '<ul>'; | |
$.each(data.feed.entry, 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>'; | |
done(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; | |
} | |
/*html = */createPlayList(appendToDom); | |
//html = '<span>' + settings.height + '</span>' + embedYoutubePlayer(); | |
//this.append(html); | |
return this; | |
}; | |
})( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment