forked from AnuragMishra/YoutubePlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYoutubePlayer.min.js
4 lines (4 loc) · 1.77 KB
/
YoutubePlayer.min.js
1
2
3
4
(function(g){function d(a,c,b){this.id=a;this.videoId=c;this.handlers={};this.ref=null;this.width="425";this.height="356";this.flashVersion="8";this.params={allowScriptAccess:"always"};this.attrs={id:this.id};if(b){if(b.params){var a=b.params,c=this.params,e;for(e in a)c[e]=a[e]}if(b.attrs){e=b.attrs;var a=this.attrs,f;for(f in e)a[f]=e[f]}if(b.width)this.width=b.width;if(b.height)this.height=b.height;if(b.flashVersion)this.flashVersion=b.flashVersion}this.embed();d.register(this)}d.prototype.embed=
function(){var a;a="http://www.youtube.com/v/{videoId}?enablejsapi=1&playerapiid={playerId}&version=3".replace("{videoId}",this.videoId);a=a.replace("{playerId}",this.id);if(!swfobject)throw new ReferenceError("YoutubePlayer depends on the SWFObject library but it is missing.");var c=this;swfobject.embedSWF(a,this.id,this.width,this.height,this.flashVersion,null,null,this.params,this.attrs,function(a){c.ref=a.ref})};d.prototype.on=function(a,c){this.handlers[a]=this.handlers[a]||[];this.handlers[a].push(c)};
d.prototype.onReady=function(){var a=document.getElementById(this.id),c='YoutubePlayer.dispatchEvent("{id}")'.replace("{id}",this.id);a.addEventListener("onStateChange",c)};d.prototype.notifyEvent=function(a){var c=d.STATES,b;for(b in c)c[b]==a&&this.fireEvent(b)};d.prototype.fireEvent=function(a){var c=this.handlers[a];if(c)for(var b=0;b<c.length;b++)c[b](a)};d.instances=[];d.register=function(a){this.instances.push(a)};d.findById=function(a){for(var c=null,b=0;b<this.instances.length;b++)this.instances[b].id==
a&&(c=this.instances[b]);return c};d.dispatchEvent=function(a){var c=d.findById(a);return function(a){c.notifyEvent(a)}};d.STATES={unstarted:-1,ended:0,playing:1,paused:2,buffering:3,cued:5};g.YoutubePlayer=d;g.onYouTubePlayerReady=function(a){d.findById(a).onReady()}})(window);