-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.ytVideos.min.js
More file actions
7 lines (7 loc) · 3.07 KB
/
jquery.ytVideos.min.js
File metadata and controls
7 lines (7 loc) · 3.07 KB
1
2
3
4
5
6
7
(function(d){d.fn.ytVideos=function(a){return this.each(function(){var g=g,e=d(this);a=d.extend({embed:!0,rowSize:0,user:"",playlist:"",count:50},a);var b=e.text(),c="?v=2&alt=jsonc";/youtube user:/i.test(b)&&(a=d.extend(a,{user:b.replace(/youtube user:/i,"")}),b="");/youtube playlist:/i.test(b)&&(a=d.extend(a,{playlist:b.replace(/youtube playlist:/i,"")}),b="");!0==a.lightbox&&(a=d.extend(a,{embed:!0}));c=0<a.playlist.length?"http://gdata.youtube.com/feeds/api/playlists/"+a.playlist+c:0<a.user.length?
"http://gdata.youtube.com/feeds/api/users/"+a.user+"/uploads"+c:"http://gdata.youtube.com/feeds/api/videos"+c;b=b.replace(/youtube (id|video|keyword|gallery):/i,"");null!=b&&0<b.length&&(c+="&q="+b);0<a.count&&(c+="&max-results="+a.count);c+="&callback=?";ytDone=!1;e.empty();d.getJSON(c,function(b){if(b.data.itemsPerPage>1&&a.count>1){e.append('<div class="ytThumbs" />');var c=e.find("div.ytThumbs")}if(b.data.totalItems>0){d.each(b.data.items,function(d,f){if(f.video!=void 0)var i=f.video.id,h=f.video.title,
j=f.video.player["default"],k=f.video.thumbnail.sqDefault;else{i=f.id;h=f.title;j=f.player["default"];k=f.thumbnail.sqDefault}if(d==0&&a.embed){e.prepend('<div class="ytPlayer '+a.olclass+'" id="ytPlayer"><div id="ytPlayerInternal" /></div>');var l=document.createElement("script");l.src="http://www.youtube.com/player_api";var m=document.getElementsByTagName("script")[0];m.parentNode.insertBefore(l,m);onYouTubePlayerAPIReady=function(){g=new YT.Player("ytPlayerInternal",{height:"100%",width:"100%",
videoId:i,playerVars:{autohide:3,controls:1,rel:0,modestbranding:1,showinfo:1},events:{onStateChange:function(b){if(b.data==YT.PlayerState.PLAYING&&!ytDone){a.ga&&_gat._getTrackerByName()._trackEvent("Media","YouTube Video",j);ytDone=true}}}})}}b.data.itemsPerPage>1&&c.append('<div class="ytThumb"><a class="ytLink" href="'+j+'" target="_blank" data-video="'+i+'" rel="#ytPlayer"><img src="'+k+'" alt="'+h+'" title="'+h+'" /><div class="ytTitle">'+h+"</div></a></div>")});e.append('<div style="clear:both"></div>');
a.tooltips==true&&setTimeout(function(){e.find("div.ytThumbs div.ytThumb img").tooltip({effect:"slide",position:"center right",offset:[0,10],opacity:0.9,predelay:200})},500);a.rowSize!=0&&setTimeout(function(){e.find("div.ytThumbs div.ytThumb:nth-child("+a.rowSize+"n)").addClass("last")},500);e.find("a.ytLink").click(function(b){if(a.embed==true){b.preventDefault();var b=d(this),c=b.attr("data-video"),e=b.attr("href");d("#ytPlayerInternal").replaceWith('<div id="ytPlayerInternal" /></div>');delete g;
ytDone=false;g=new YT.Player("ytPlayerInternal",{height:"100%",width:"100%",videoId:c,playerVars:{autoplay:1,autohide:3,controls:1,rel:0,modestbranding:1,showinfo:1},events:{onStateChange:function(b){if(b.data==YT.PlayerState.PLAYING&&!ytDone){a.ga&&_gat._getTrackerByName()._trackEvent("Media","YouTube Video",e);ytDone=true}}}});a.lightbox==true&&b.overlay({expose:{color:"#000",loadSpeed:200,opacity:0.7,onClose:function(){g.destroy()}},load:true}).load()}else if(a.ga&&!ytDone){_gat._getTrackerByName()._trackEvent("Media",
"YouTube Video",d(this).attr("href"));ytDone=true}})}})})}})(jQuery);