-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjquery.ytChanPlayer.min.js
More file actions
6 lines (6 loc) · 2.28 KB
/
jquery.ytChanPlayer.min.js
File metadata and controls
6 lines (6 loc) · 2.28 KB
1
2
3
4
5
6
/* jQuery Youtube Channel Player 0.1.3
* Author: Marc Loehe (boundaryfunctions)
* Based on jQuery.youtubeChannel by Miguel Guerreiro (dharyk)
* Licensed under the MIT license
*/
(function(a){"use strict";a.fn.ytChanPlayer=function(b){var c=a(this),d,e=a("<ul/>",{"class":"yt-channel-list"}),f=a.extend({},{username:"",query:"",startIndex:1,maxResults:10,orderBy:"published",playerOpts:{autohide:1,autoplay:0,egm:1,fs:1,showinfo:0,wmode:"opaque"}},b),g=[],h=function(){var a="https://gdata.youtube.com/feeds/api/videos",b=["alt=json","orderby="+f.orderBy,"start-index="+f.startIndex,"max-results="+f.maxResults,"callback=?"];if(f.username!==""){b.push("author="+f.username)}else if(f.query!==""){b.push("q="+encodeURIComponent(f.query))}return a+"?"+b.join("&")},i=function(b){if(b.length>0){if(!d){d=a("<iframe/>",{"class":"yt-player"})}var e="http://www.youtube-nocookie.com/embed/"+b,g;if(f.playerOpts){e+="?";for(g in f.playerOpts){if(f.playerOpts.hasOwnProperty(g)){e+=g+"="+f.playerOpts[g]+"&"}}e+="_a=b"}d.attr("src",e).prependTo(c)}},j=function(a,b){b-=a.toString().length;if(b>0){return[b+(/\./.test(a)?2:1)].join("0")+a}return a.toString()},k=function(a){var b,c=parseInt(a,10);b=Math.floor(c/60);c-=b*60;return b+":"+j(c,2)};c.addClass("yt-channel-holder");e.appendTo(c);a.getJSON(h(),function(b){var c,d,h,j;if(b.feed.entry){if(f.sticky){i(f.sticky)}else{i(b.feed.entry[0].id.$t.match("[^/]*$"))}for(c=0;c<b.feed.entry.length;c++){j=b.feed.entry[c];h={link:j?j.media$group.media$player[0].url:"",title:j?j.media$group.media$title.$t:"",thumb:j?j.media$group.media$thumbnail[1].url:"",duration:j?j.media$group.yt$duration.seconds:0,views:j&&j.yt$statistics?j.yt$statistics.viewCount:0,id:j?j.id.$t.match("[^/]*$"):""};d=a("<li/>",{"class":"yt-channel-video"}).html(['<a href="',h.link,'" title="',h.title," (",k(h.duration),')" target="_blank">','<img class="vid-thumb" alt="',h.title,'" src="',h.thumb,'"/>',"</a>"].join("")).data("id",h.id).click(function(b){b.preventDefault();f.playerOpts=a.extend(f.playerOpts,{autoplay:1});i(a(this).data("id"))}).css("opacity",".7").hover(function(){a(this).stop().animate({opacity:"1"},400)},function(){a(this).stop().animate({opacity:".7"},200)});g.push(h);d.appendTo(e)}}else{a("<li/>",{"class":"yt-channel-video"}).html("<a>NO RESULTS</a>").appendTo(e)}});return this}})(jQuery)