How can I embed youtube videos using jQuery?
I am using drupal 6.22 and i want to show my youtube image video with title, posted date and views.
I was looking for a module but i think it is better create a block with json. The problem is drupal jquery older than my script and everything explode.
Result:
Image 1 Title = Teo Unified 2010 Jul 9 2010 | 264 viewsImage 2
Title = Teo Communications 2010 Jul 9 2010 | 264 viewsImage 3
Title = Unified free Jul 9 2010 | 264 viewsMy code is:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="/sites/all/modules/jquery_update/replace/jquery.min.js"></script>
<script type="text/javascript">
(function($){
$.getJSON(
"http://gdata.youtube.com/feeds/api/videos?max-results=5&开发者_开发知识库orderby=published",
{
author:"MrTeotech",
alt:"json",
},
function(data) {
$.each(data.feed.entry, function(i, item) {
var updated = item.updated;
var title = item.title['$t'];
var url = item['media$group']['media$content'][0]['url'];
var link = item['link'][0]['href'];
var thumb = item['media$group']['media$thumbnail'][0]['url'];
var numViews = item['yt$statistics']['viewCount'];
var month=new Array(12);
month[0]="Jan";
month[1]="Feb";
month[2]="Mar";
month[3]="Apr";
month[4]="May";
month[5]="Jun";
month[6]="Jul";
month[7]="Aug";
month[8]="Sep";
month[9]="Oct";
month[10]="Nov";
month[11]="Dec";
var date = new Date(item['published']['$t']);
var date = month[date.getMonth()] + " " + date.getDate() + " " + date.getFullYear();
$("#output").append("<div><div class=\"izq\"><a target=\"new\" href=\""+link+"\"><img src=\""+thumb+"\" height=\"80px\"/></a></div><div class=\"der\"><a target=\"new\" href=\""+link+"\">"+title+"</a><br/><br/>"+date + " | "+ numViews+" views" + "</div></div>");
});
});
})(jQuery);
You can embed Youtube videos with JQuery using the Flash plugin. Here's the syntax for embedding a Youtube video. You can specify the width and height.
<p><a href="http://www.youtube.com/v/rFY1AF4r3Ts">My great YouTube video</a></p>
http://jquery.lukelutman.com/plugins/flash/
精彩评论