-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjQuery.tubeplayer.min.js
18 lines (18 loc) · 8.75 KB
/
jQuery.tubeplayer.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
(function(e){function k(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=Math.random()*16|0;return(a=="x"?b:b&3|8).toString(16)})}var d={};d.ytplayers={};d.inits=[];d.iframeScriptInited=false;d.inited=false;e.tubeplayer={};e.tubeplayer.TubePlayer=d;e.tubeplayer.events={};e.tubeplayer.defaults={afterReady:function(){},stateChange:function(a){var b=this.onPlayer;return function(c){if(typeof c==="object")c=c.data;switch(c){case -1:return b.unstarted[a]();case 0:return b.ended[a]();
case 1:return b.playing[a]();case 2:return b.paused[a]();case 3:return b.buffering[a]();case 5:return b.cued[a]();default:return null}}},onError:function(a){var b=this.onErr;return function(c){if(typeof c==="object")c=c.data;switch(c){case 2:return b.invalidParameter[a]();case 100:return b.notFound[a]();case 101:case 150:return b.notEmbeddable[a]();default:return null}}},qualityChange:function(a){var b=this;return function(c){if(typeof c==="object")c=c.data;return b.onQualityChange[a](c)}},onQualityChange:{},
onPlayer:{unstarted:{},ended:{},playing:{},paused:{},buffering:{},cued:{}},onErr:{notFound:{},notEmbeddable:{},invalidParameter:{}}};var l={width:425,height:355,allowFullScreen:"true",initialVideo:"DkoeNLuMbcI",start:0,preferredQuality:"default",showControls:true,showRelated:false,annotations:true,autoPlay:false,autoHide:true,loop:0,theme:"dark",color:"red",showinfo:false,modestbranding:true,protocol:"http",wmode:"transparent",swfobjectURL:"ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js",
loadSWFObject:true,allowScriptAccess:"always",playerID:"tubeplayer-player-container",iframed:true,onPlay:function(){},onPause:function(){},onStop:function(){},onSeek:function(){},onMute:function(){},onUnMute:function(){},onPlayerUnstarted:function(){},onPlayerEnded:function(){},onPlayerPlaying:function(){},onPlayerPaused:function(){},onPlayerBuffering:function(){},onPlayerCued:function(){},onQualityChange:function(){},onErrorNotFound:function(){},onErrorNotEmbeddable:function(){},onErrorInvalidParameter:function(){}};
e.fn.tubeplayer=function(a,b){var c=e(this),f=typeof a;if(arguments.length===0||f==="object")return c.each(function(){d.init(e(this),a)});else if(f==="string")return c.triggerHandler(a+".tubeplayer",b||null)};var g=function(a){return function(b,c){var f=d.getPkg(b);if(f.ytplayer){b=a(b,c,f);if(typeof b==="undefined")b=f.$player;return b}return f.$player}};e.tubeplayer.getPlayers=function(){return d.ytplayers};d.init=function(a,b){if(a.hasClass("jquery-youtube-tubeplayer"))return a;b=e.extend({},l,
b);b.playerID+="-"+k();a.addClass("jquery-youtube-tubeplayer").data("opts.tubeplayer",b);for(var c in j)a.bind(c+".tubeplayer",a,j[c]);d.initDefaults(e.tubeplayer.defaults,b);e("<div></div>").attr("id",b.playerID).appendTo(a);d.initPlayer(a,b);return a};d.getPkg=function(a){a=a.data;var b=a.data("opts.tubeplayer");return{$player:a,opts:b,ytplayer:d.ytplayers[b.playerID]}};d.iframeReady=function(a){d.inits.push(function(){new YT.Player(a.playerID,{videoId:a.initialVideo,width:a.width,height:a.height,
playerVars:{autoplay:a.autoPlay?1:0,autohide:a.autoHide?1:0,controls:a.showControls?1:0,loop:a.loop?1:0,playlist:a.loop?a.initialVideo:"",rel:a.showRelated?1:0,fs:a.allowFullScreen?1:0,wmode:a.wmode,showinfo:a.showinfo?1:0,modestbranding:a.modestbranding?1:0,iv_load_policy:a.annotations?1:3,start:a.start,theme:a.theme,color:a.color},events:{onReady:function(b){d.ytplayers[a.playerID]=b.target;b=e(b.target).parents(".jquery-youtube-tubeplayer");e.tubeplayer.defaults.afterReady(b)},onPlaybackQualityChange:e.tubeplayer.defaults.qualityChange(a.playerID),
onStateChange:e.tubeplayer.defaults.stateChange(a.playerID),onError:e.tubeplayer.defaults.onError(a.playerID)}})});if(d.inits.length>=1&&!d.inited)return function(){for(var b=0;b<d.inits.length;b++)d.inits[b]();d.inited=true};d.inited&&d.inits.pop()();return window.onYouTubePlayerAPIReady};d.supportsHTML5=function(){return!!document.createElement("video").canPlayType};d.initDefaults=function(a,b){var c=b.playerID,f=a.onPlayer;f.unstarted[c]=b.onPlayerUnstarted;f.ended[c]=b.onPlayerEnded;f.playing[c]=
b.onPlayerPlaying;f.paused[c]=b.onPlayerPaused;f.buffering[c]=b.onPlayerBuffering;f.cued[c]=b.onPlayerCued;a.onQualityChange[c]=b.onQualityChange;a=a.onErr;a.notFound[c]=b.onErrorNotFound;a.notEmbeddable[c]=b.onErrorNotEmbeddable;a.invalidParameter[c]=b.onErrorInvalidParameter};d.initPlayer=function(a,b){b.iframed&&d.supportsHTML5()?d.initIframePlayer(a,b):d.initFlashPlayer(a,b)};d.initIframePlayer=function(a,b){if(!d.iframeScriptInited){a=document.createElement("script");a.src=b.protocol+"://www.youtube.com/iframe_api";
var c=document.getElementsByTagName("script")[0];c.parentNode.insertBefore(a,c);d.iframeScriptInited=true}window.onYouTubePlayerAPIReady=d.iframeReady(b)};d.initFlashPlayer=function(a,b){if(b.loadSWFObject){b.swfobjectURL=b.swfobjectURL.replace("http://","");b.swfobjectURL=b.swfobjectURL.replace("https://","");b.swfobjectURL=b.protocol+"://"+b.swfobjectURL;e.getScript(b.swfobjectURL,d.initFlashPlayerFN(b))}else d.initFlashPlayerFN(b)()};d.initFlashPlayerFN=function(a){return function(){var b=["//www.youtube.com/v/"];
b.push(a.initialVideo);b.push("?&enablejsapi=1&version=3");b.push("&playerapiid="+a.playerID);b.push("&rel= "+(a.showRelated?1:0));b.push("&autoplay="+(a.autoPlay?1:0));b.push("&autohide="+(a.autoHide?1:0));b.push("&loop="+(a.loop?1:0));b.push("&playlist="+(a.loop?a.initialVideo:""));b.push("&controls="+(a.showControls?1:0));b.push("&showinfo="+(a.showinfo?1:0));b.push("&modestbranding="+(a.modestbranding?1:0));b.push("&iv_load_policy="+(a.annotations?1:3));b.push("&start="+a.start);b.push("&theme="+
a.theme);b.push("&color="+a.color);b.push("&fs="+(a.allowFullScreen?1:0));swfobject.embedSWF(b.join(""),a.playerID,a.width,a.height,"8",null,null,{allowScriptAccess:a.allowScriptAccess,wmode:a.wmode,allowFullScreen:a.allowFullScreen},{id:a.playerID});window.onYouTubePlayerReady=function(c){var f=document.getElementById(c),h=c.replace(/-/g,""),i=e.tubeplayer.defaults;e.tubeplayer.events[h]={stateChange:i.stateChange(c),error:i.onError(c),qualityChange:i.qualityChange(c)};f.addEventListener("onStateChange",
"$.tubeplayer.events."+h+".stateChange");f.addEventListener("onError","$.tubeplayer.events."+h+".error");f.addEventListener("onPlaybackQualityChange","$.tubeplayer.events."+h+".qualityChange");d.ytplayers[c]=f;c=e(f).parents(".jquery-youtube-tubeplayer");e.tubeplayer.defaults.afterReady(c)}}};d.getVideoIDFromURL=function(a){a=a||"";var b=a.indexOf("?");a=a.substring(b,a.length);b=a.indexOf("v=");if(b>-1){var c=a.indexOf("&",b);if(c===-1)c=a.length;return a.substring(b+2,c)}return""};var j={cue:g(function(a,
b,c){c.ytplayer.cueVideoById(b,c.opts.preferredQuality)}),play:g(function(a,b,c){if(typeof b==="object")c.ytplayer.loadVideoById(b.id,b.time,c.opts.preferredQuality);else b?c.ytplayer.loadVideoById(b,0,c.opts.preferredQuality):c.ytplayer.playVideo();c.opts.onPlay(b)}),pause:g(function(a,b,c){c.ytplayer.pauseVideo();c.opts.onPause(c)}),stop:g(function(a,b,c){c.ytplayer.stopVideo();c.opts.onStop(c)}),seek:g(function(a,b,c){c.ytplayer.seekTo(b,true);c.opts.onSeek(b)}),mute:g(function(a,b,c){c.$player.attr("data-prev-mute-volume",
c.ytplayer.getVolume());c.ytplayer.mute();c.opts.onMute(c)}),unmute:g(function(a,b,c){c.ytplayer.unMute();c.ytplayer.setVolume(c.$player.attr("data-prev-mute-volume")||50);c.opts.onUnMute()}),isMuted:g(function(a,b,c){return c.ytplayer.isMuted()}),volume:g(function(a,b,c){if(b){c.ytplayer.setVolume(b);c.$player.attr("data-prev-mute-volume",c.ytplayer.getVolume())}else return c.ytplayer.getVolume()||0}),quality:g(function(a,b,c){if(b)c.ytplayer.setPlaybackQuality(b);else return c.ytplayer.getPlaybackQuality()}),
data:g(function(a,b,c){a={};c=c.ytplayer;a.bytesLoaded=c.getVideoBytesLoaded();a.bytesTotal=c.getVideoBytesTotal();a.startBytes=c.getVideoStartBytes();a.state=c.getPlayerState();a.currentTime=c.getCurrentTime();a.duration=c.getDuration();a.videoURL=c.getVideoUrl();a.getVideoEmbedCode=c.getVideoEmbedCode();a.videoID=d.getVideoIDFromURL(a.videoURL);a.availableQualityLevels=c.getAvailableQualityLevels();return a}),videoId:g(function(a,b,c){return d.getVideoIDFromURL(c.ytplayer.getVideoUrl())}),size:g(function(a,
b,c){if(b.width&&b.height){c.ytplayer.setSize(b.width,b.height);e(c.ytplayer).css(b)}}),destroy:g(function(a,b,c){c.$player.removeClass("jquery-youtube-tubeplayer").data("opts.tubeplayer",null).unbind(".tubeplayer").html("");delete d.ytplayers[c.opts.playerID];a=e.tubeplayer.defaults;b=["unstarted","ended","playing","paused","buffering","cued"];for(var f in b)delete a.onPlayer[b[f]][c.opts.playerID];b=["notFound","notEmbeddable","invalidParameter"];for(f in b)delete a.onErr[b[f]][c.opts.playerID];
delete a.onQualityChange[c.opts.playerID];delete e.tubeplayer.events[c.opts.playerID];e(c.ytplayer).remove();return null}),player:g(function(a,b,c){return c.ytplayer})}})(jQuery);