Hi guys, Today I am going to share how to search youtube videos instantly using a simple jquery ajax function
Contents
Jquery Plugin Code
(function( $ ) {
$.fn.YoutubeVideo = function (pars) {
var feeddiv = $(this);
var pubdt;
$(this).html("<center>"+pars.loadingtext+"</center>");
$.ajax({type:"GET",url:pars.feedurl+"&max-results="+pars.count,dataType:"jsonp",success:function(yt_data){
feeddiv.html('');
$.each(yt_data.data.items,function(i,entry){
var video_id=entry.id;
var video_frame="<iframe width='"+pars.width+"' height='"+pars.height+"' src='http://www.youtube.com/embed/"+video_id+"' frameborder='0' type='text/html'></iframe>";
pubdt=new Date(entry.updated);
feeddiv.append('<div class="frame">');
feeddiv.append('<div class="ItemTitle">'+entry.title+' - <span class="ItemDate">'+pubdt.toLocaleDateString()+'</span></div>');
feeddiv.append('<div class="video">'+video_frame+'</div>');
feeddiv.append('</div>');
}) }
});
}})( jQuery );// JavaScript Document
Simple Jquery code
$('#video_loader').YoutubeVideo({
feedurl:'http://gdata.youtube.com/feeds/api/videos?q='+s_text+'&v=2&format=5&alt=jsonc', // your rss feed url here...
count:'5', // total no of videos
height:'259', //video height
width:'450', //video width
loadingtext:'fetching videos from youtube' //loading text...
});
Plugin Configurations
- No of videos
- Video Height
- Video Width
- Loading text etc
Please don’t forget to share and subscribe to latest updates of the blog. Also any comments and feedback are all welcome!
Thanks!
Hi, first off I want to say that this script is awesome. Thank you for writing it, I appreciate it!
Secondly, is there a way to make it so it shows the suggestions right below the search bar (only the thumbnail & title not the actual video) Thanks!
Hi Ticker,
Thanks for your comment. 🙂
As per your suggestion I have wrote a new script which will show you only the thumbnail & title.
Check it out from here & let me know your feedback – http://w3lessons.info/demo/youtube-search-plugin/index1.html
Thanks
Karthikeyan K