//------------------------------------------------- // youtube playlist jquery plugin // Created by dan@geckonm.com // www.geckonewmedia.com // // v1.1 - updated to allow fullscreen // - thanks Ashraf for the request //------------------------------------------------- jQuery.fn.ytplaylist = function(options) { // default settings var options = jQuery.extend( { holderId: 'ytvideo', playerHeight: '', playerWidth: '', addThumbs: false, thumbSize: 'grande', showInline: false, autoPlay: true, showRelated: false, allowFullScreen: false, tipo:1 },options); return this.each(function() { var selector = $(this); var autoPlay = ""; var showRelated = "&rel=0"; var fullScreen = ""; if(options.autoPlay) autoPlay = "&autoplay=1"; if(options.showRelated) showRelated = "&rel=1"; if(options.allowFullScreen) fullScreen = "&fs=1"; //throw a youtube player in function play(id,autoPlay) { var html = ''; if(id){ if(autoPlay) autoPlay = "&autoplay=1"; else autoPlay = "&autoplay=0"; html += ''; html += ' '; html += ' '; if(options.allowFullScreen) { html += ' '; } html += ''; html += ''; }else{ id=getVimeoId(firstVid); html+=''; } return html; }; function playVimeo(id,autoPlay) { var html = ''; //id=getVimeoId(firstVid); html+=''; return html; }; //grab a youtube id from a (clean, no querystring) url (thanks to http://jquery-howto.blogspot.com/2009/05/jyoutube-jquery-youtube-thumbnail.html) function getVimeoId(url) { if(url.toLowerCase().indexOf('vimeo') > 0) { var re = new RegExp('/[0-9]+', "g"); var match = re.exec(url); if (match == null) { return false; } else { return match[0].substring(1); } } return false; }; function youtubeid(url) { var ytid = url.match("[\\?&]v=([^&#]*)"); if(ytid!=null){ ytid = ytid[1]; return ytid; }else return false; /*else{ var id=getVimeoId(url); return id; }*/ }; //load inital video var firstVid = selector.children("li:first-child").addClass("currentvideo").children("a").attr("href"); if(firstVid){ $("#"+options.holderId+"").html(play(youtubeid(firstVid),false)); //load video on request selector.children("li").children("a").click(function() { if(options.showInline) { $("li.currentvideo").removeClass("currentvideo"); $(this).parent("li").addClass("currentvideo").html(play(youtubeid($(this).attr("href")),false)); } else { if(youtubeid($(this).attr("href"))){ idV=youtubeid($(this).attr("href")); $("#"+options.holderId+"").html(play(idV,true)); } else{ idV=getVimeoId($(this).attr("href")); $("#"+options.holderId+"").html(playVimeo(idV,true)); } $(this).parent().parent("ul").find("li.currentvideo").removeClass("currentvideo"); $(this).parent("li").addClass("currentvideo"); } return false; }); //do we want thumns with that? if(options.addThumbs) { selector.children().each(function(i){ var replacedText = $(this).text(); if(options.thumbSize == 'gigante'){ var thumbUrl = url; }else{ var idy=youtubeid($(this).children("a").attr("href")) if(idy){ if(options.thumbSize == 'small') { var thumbUrl = "http://img.youtube.com/vi/"+youtubeid($(this).children("a").attr("href"))+ "/1.jpg"; } else { var thumbUrl = "http://img.youtube.com/vi/"+youtubeid($(this).children("a").attr("href"))+ "/0.jpg"; } $(this).children("a").empty().html(""+replacedText+""+replacedText).attr("title", replacedText); } } }); } } }); };