-
Notifications
You must be signed in to change notification settings - Fork 24
/
html5-youtube.compat.min.js
2 lines (2 loc) · 2.99 KB
/
html5-youtube.compat.min.js
1
2
/*! @license html5-youtube.js by Ginpei https://github.com/ginpei/html5-youtube.js MIT License */
!function(e,t,i){var r=Array.prototype.slice,n=i.prototype;i.bind=function(e,t){var i=r.call(arguments,2);return function(){var n=i.concat(r.call(arguments));return e.apply(t,n)}},i._execDefineProperty=function(e,t,i){e[t]=function(e){return arguments.length>0?(i.set.call(this,e),e):i.get.call(this)}},i.registerYouTubePlayerReady=function(t,i){e.onYouTubePlayerReady||(e.onYouTubePlayerReady=this.bind(this.onYouTubePlayerReady,this),this._callbacksForYouTubePlayerReady={}),this._callbacksForYouTubePlayerReady[t]=i},i.onYouTubePlayerReady=function(e){this._style||(this._style=t.styleSheets[t.styleSheets.length-1]),this._callbacksForYouTubePlayerReady[e].onYouTubePlayerReady(e)},n._initializeEventer=function(){},n._clearEventer=function(){},n._buildPlayer=function(t){var r=this._getVideoOptions(t);if(r.videoId||(r.videoId="xxxxxxxxxxx"),!e.swfobject)throw new Error('swfobject is required. Use this code:\n<script src="//cdnjs.cloudflare.com/ajax/libs/swfobject/2.2/swfobject.js"><\/script>');this._originalElemId=r.el.id;var n=r.el.id="youtubejs"+Date.now();this._elOriginal=r.el,i.registerYouTubePlayerReady(n,this);var a="http://www.youtube.com/v/"+r.videoId+"?wmode=opaque&fs=0&enablejsapi=1&version=3&playerapiid="+n,o={allowScriptAccess:"always",wmode:"transparent"},l={id:n};swfobject.embedSWF(a,n,r.width,r.height,"8",null,null,o,l)},n._destroyPlayer=function(){var e=this.player;this.player.destroy(),this.player=null;var t=this._elOriginal;this._originalElemId?t.id=this._originalElemId:t.removeAttribute("id"),this._elOriginal=null;var i=e.parentNode;i.insertBefore(t,e),i.removeChild(e),this._clearYTStyle(t.id),this._elOriginal=null},n._clearYTStyle=function(e){for(var t="#"+e,r=i._style,n=r.cssRules||r.rules,a=0,o=n.length;a<o;a++){if(n[a].selectorText===t){r.deleteRule?r.deleteRule(a):r.removeRule(a);break}}},n.onYouTubePlayerReady=function(e){var i=this.player=t.getElementById(e),r=e.replace(/-/g,"_");this._registerVideoEvents(i,r);var n={type:"onReady",data:null,target:i};this.onReady(n)},n._registerVideoEvents=function(e,t){this._registerVideoEvent(e,t,"onApiChang"),this._registerVideoEvent(e,t,"onError"),this._registerVideoEvent(e,t,"onPlaybackQualityChange"),this._registerVideoEvent(e,t,"onPlaybackRateChange"),this._registerVideoEvent(e,t,"onReady"),this._registerVideoEvent(e,t,"onStateChange")},n._registerVideoEvent=function(t,r,n){var a=r+n;t.addEventListener(n,a),e[a]=i.bind(function(e,t){try{var i={type:e,data:t,target:this};this[e](i)}catch(e){console.error(e)}},this,n)},n.addEventListener=function(e,t){this._pushListener(e,t)},n.removeEventListener=function(e,t){this._popListener(e,t)},n.trigger=function(e,i){var r,n=this._events[e];if(n){t.createEvent?(r=t.createEvent("CustomEvent"),r.initEvent(e,!1,!0)):(r=t.createEventObject(),r.type=e),r.player=this,i&&(r.playerData=i.data,r.originalEvent=i);for(var a=0,o=n.length;a<o;a++){var l=n[a];l&&l.binded(r)}return this}}}(window,document,window.youtube.Player);