-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgwdyoutube_min.js
More file actions
22 lines (22 loc) · 12.1 KB
/
gwdyoutube_min.js
File metadata and controls
22 lines (22 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
(function(){'use strict';var f;var h=function(a){return"gwd-page"==a.tagName.toLowerCase()||"gwd-page"==a.getAttribute("is")},l=function(a){if(h(a))return a;for(;a&&9!=a.nodeType;)if((a=a.parentElement)&&h(a))return a;return null};var n=function(){var a=window.navigator.userAgent||"";return-1<a.indexOf("Trident")||-1<a.indexOf("MSIE")};var p=function(a,b){return setTimeout(a,b)};var r=function(a,b){var c=document.createEvent("Event");c.initEvent(a,!0,!0);b.dispatchEvent(c)},u=function(a,b){var c=function(d){a.removeEventListener("load",c);b(d)};a.addEventListener("load",c)},v=function(a){var b=!1,c=null;return function(){b=!0;c||(b&&(a(),b=!1),c=p(function(){c=null;b&&(a(),b=!1)},30))}};function w(a,b){this.D=a;a=b.split(".");b=window;for(var c=0;b&&c<a.length;c++)b=b[a[c]];this.u=b?0:2;this.f=[]}w.prototype.N=function(){for(var a=this.u=0;a<this.f.length;a++)this.f[a]();this.f=[]};w.prototype.load=function(a){a&&(0==this.u?a():this.f.push(a));if(2==this.u){this.u=1;a=document.createElement("script");a.type="text/javascript";a.async=!0;a.src=this.D;u(a,this.N.bind(this));var b=document.getElementsByTagName("script")[0];b?b.parentNode.insertBefore(a,b):document.getElementsByTagName("head")[0].appendChild(a)}};function x(){this.D="https://www.youtube.com/iframe_api";this.L="YT";this.C=null;this.f=[];this.G=!1}x.prototype.load=function(a){this.G?a():(this.C||(this.C=new w(this.D,this.L)),this.C.load(),this.f.push(a))};var y=null;window.onYouTubeIframeAPIReady=function(){r("apiloaded",document);var a=y;a.G=!0;for(var b=0;b<a.f.length;b++)a.f[b]();a.f=[]};
var z=function(a){var b="https://www.youtube.com/embed/"+a.videoId;b+="?enablejsapi=1&html5=1";a.autoplay&&(b+="&autoplay=1");a.mute&&(b+="&mute=1");a.allowfullscreen||(b+="&fs=0");a.adformat&&(b+="&adformat="+a.adformat);n()&&(b+="&wmode=opaque");a.color&&(b+="&color="+a.color);b+="&controls=";switch(a.controls){case "none":b+="0";break;case "autohide":case void 0:b+="1"}a.annotations||(b+="&iv_load_policy=3");a.related||(b+="&rel=0");a.loop&&(b+="&loop=1&playlist="+a.videoId);a.title||(b+="&showinfo=0");
a.startPosition&&(b+="&start="+a.startPosition);a.extraPlayerArgs&&a.extraPlayerArgs.split("&").forEach(function(a){a&&(a=a.split("="),b+="&",b+=a[0],1<a.length&&(b+="="+encodeURIComponent(a[1])))});return b},A=function(a){a||(a=Date.now()+""+Math.floor(1E4*Math.random()));return"video"+a},B=function(a,b,c,d){y||(y=new x);var g=!1;y.load(function(){if(!g){var e=c.width;var q=c.height,m=z(c),t=c.allowfullscreen,k=a.querySelector("#"+b);k||(k=document.createElement("iframe"),k.id=b,k.frameBorder="0",
k.type="text/html",a.appendChild(k));m!=k.src&&(k.src=m);k.width=e;k.height=q;t?k.setAttribute("allowfullscreen",""):k.removeAttribute("allowfullscreen");e=new YT.Player(b,{events:c.events});d(e)}});return function(){g=!0}};var C=/^https:\/\/((?:www|m).)youtube.com(\/.*)?$/,D=function(a){a=a||"";var b=a.match(/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&\?]*).*/);return b&&11==b[2].length?b[2]:a},E=function(){};goog.inherits(E,HTMLElement);E.prototype.createdCallback=function(){this.a=null;this.g=!1;this.h="";this.j=this.s=!1;this.m=null;this.F=this.B=!1;this.c=[];this.J=[];this.v=this.b=null;this.w=this.i=!1;this.o=-1;this.I=v(this.K.bind(this))};
var G=function(a,b){if(!a.b){a.style.position="relative";var c=window.getComputedStyle(a).height,d=window.getComputedStyle(a).width;a.b=document.createElement("div");a.b.className="youtube-overlay";a.b.style.height=c;a.b.style.width=d;if(b){a.b.className+=" youtube-play-button";a.b.style.backgro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ywxLjU2Ny00LjAzMywyLjYtNS4xYzEuMzY3LTEuNDM0LDIuOTY3LTIuNDM0LDQuOC0zYzAuNjMzLTAuMTY3LDEuMzMzLTAuMywyLjEtMC40YzAuNC0wLjA2NiwwLjkxNy0wLjEzMywxLjU1LTAuMmM0LjktMC4zMzMsMTEuMjgzLTAuNTY3LDE5LjE1LTAuN0MzNS42NSwwLjA1LDM5LjA4MywwLDQyLjA1LDBMNDUsMC4wNWMyLjQ2NywwLDQuOTMzLDAuMDM0LDcuNCwwLjFjNy44MzMsMC4xMzMsMTQuMiwwLjM2NywxOS4xLDAuN2MwLjMsMC4wMzMsMC44MzMsMC4xLDEuNiwwLjJjMC43MzMsMC4xLDEuNDE3LDAuMjMzLDIuMDUsMC40YzEuODMzLDAuNTY2LDMuNDM0LDEuNTY2LDQuOCwzYzEuMDY2LDEuMDY2LDEuOTMzLDIuNzY3LDIuNiw1LjFjMC4zNjcsMS4yLDAuNjE3LDIuMjg0LDAuNzUsMy4yNWwwLjQsNC4yNUM4NCwyMC40NSw4NC4xNSwyMy41NjcsODQuMTUsMjYuNHogTTMzLjMsNDEuNEw1NiwyOS42TDMzLjMsMTcuNzVWNDEuNHonIGZpbGw9JyNDQzE4MUUnIGZpbGwtb3BhY2l0eT0nLjUnPjwvcGF0aD48cG9seWdvbiBwb2ludHM9JzMzLjMsNDEuNCAzMy4zLDE3Ljc1IDU2LDI5LjYnIGZpbGw9JyNGRkYnPjwvcG9seWdvbj48L3N2Zz4K')";
var g=document.createElement("div");g.className="youtube-thumbnail";a.b.appendChild(g);var e={videoId:F(a).videoId,width:d,height:c,thumbWidth:"100%",thumbHeight:"100%",thumbAlign:"tl",events:{onClick:a.H.bind(a)}};p(function(){this.v=new YT.Thumbnail(g,e)}.bind(a),0)}else n()&&(a.b.style.backgroundColor="rgba(0, 0, 0, 0)")}return a.b};
E.prototype.H=function(){if(this.i){H(this);this.setAttribute("autoplay","standard");this.i=!1;this.j=!0;var a=F(this);this.h=this.h||A(this.id);this.m=B(this,this.h,a,function(a){this.a=a;r("ready",this)}.bind(this))}};
E.prototype.attachedCallback=function(){if("function"==typeof this.gwdLoad&&"function"==typeof this.gwdIsLoaded&&!this.gwdIsLoaded()){var a=l(this),b=a&&"function"==typeof a.gwdIsLoaded;(!a||b&&a.gwdIsLoaded())&&this.gwdLoad()}if(null==this.gwdActivate||"function"==typeof this.gwdActivate)null!=this.gwdIsActive&&this.gwdIsActive()||(b=(a=l(this))&&null!=a.gwdIsActive&&"function"==typeof a.gwdIsActive,null==a&&this.gwdActivate(),b&&a.gwdIsActive()&&this.gwdActivate());window.addEventListener("resize",
this.I,!1)};E.prototype.detachedCallback=function(){window.removeEventListener("resize",this.I,!1);H(this)};var H=function(a){a.a&&(a.a.destroy(),a.a=null);a.b&&a.b.parentElement&&(a.removeChild(a.b),a.b=null);a.v&&(a.v.destroy(),a.v=null);a.m&&a.m();a.g=!1;a.j=!1;a.m=null};f=E.prototype;
f.gwdLoad=function(){if(!this.j){this.j=!0;var a=F(this);this.h=this.h||A(this.id);this.m=B(this,this.h,a,function(b){this.a=b;if("preview"==a.preview||"intro"==a.preview)this.i=!0,this.appendChild(G(this,"preview"==a.preview));r("ready",this)}.bind(this))}};f.gwdIsLoaded=function(){return null!=this.a};f.gwdActivate=function(){this.classList.remove("hidden");this.s=!0};f.gwdDeactivate=function(){this.classList.add("hidden");0!=this.getCurrentTime()&&this.seek(0);this.s=!1;this.pause()};
f.gwdIsActive=function(){return this.s};f.attributeChangedCallback=function(a){if("video-url"==a&&this.j){var b=I(this);b&&(this.B=!1);this.setYouTubeId(D(this.getAttribute(a)),!b)}};f.play=function(){this.i?this.H():this.g?this.a.playVideo():this.c.push({l:0})};f.pause=function(){this.g?(5!=this.o&&2!=this.o||!this.s)&&this.a.pauseVideo():this.c.push({l:1})};f.replay=function(){this.i||(this.seek(0),this.play(),r("replayed",this))};
f.seek=function(a){this.i||(this.g?this.a.seekTo(a,!0):this.c.push({l:2,A:a}))};f.getCurrentTime=function(){return this.g?this.a.getCurrentTime():0};f.setYouTubeId=function(a,b){this.i||(this.g?b?this.a.cueVideoById(a):this.a.loadVideoById(a):this.j?this.c.push({l:4,A:a,R:b}):this.setAttribute("video-url",a))};f.toggleMute=function(){if(!this.i)if(this.g){var a=this.a;a.isMuted()?a.unMute():a.mute()}else this.c.push({l:3})};f.isMuted=function(){return this.g?this.a.isMuted():!1};
var F=function(a){var b="none",c=!1;I(a)&&(c=!0,b=String(a.getAttribute("autoplay")).toLowerCase(),b="true"==b||""==b?"standard":b);var d=J(a);c={annotations:a.hasAttribute("annotations"),autoplay:c,events:{onReady:a.O.bind(a),onStateChange:a.P.bind(a),onCueRangeEnter:a.M.bind(a)},height:d.height,loop:a.hasAttribute("loop"),mute:a.hasAttribute("muted"),preview:b,related:a.hasAttribute("related"),title:a.hasAttribute("title"),videoId:D(a.getAttribute("video-url")),width:d.width};if(d=a.getAttribute("color"))c.color=
d;if(d=a.getAttribute("controls"))c.controls=d;d=parseInt(a.getAttribute("start-position"),10);isNaN(d)||(c.startPosition=d);if(!(d=a.getAttribute("adformat")))if(d=b,window.Enabler){var g=studio.common.Environment;if(g.hasType(g.Type.CREATIVE_TOOLSET)){if("none"==d||"preview"==d)var e="2_11";g=Enabler.getContainerState();g!=studio.sdk.ContainerState.EXPANDING&&g!=studio.sdk.ContainerState.EXPANDED&&g!=studio.sdk.ContainerState.FS_EXPANDING&&g!=studio.sdk.ContainerState.FS_EXPANDED||"standard"!=d&&
"intro"!=d||(e="2_9")}else d=Enabler.getParameter("adSiteUrl")||"localhost",C.test(d)&&(e="1_8");e||(e="1_5");d=e}else d="";c.adformat=d;if("intro"==b||"preview"==b)c.annotations=!1,c.controls="none",c.loop=!1,c.related=!1,c.title=!1,c.mute=!0;if(e=a.getAttribute("extra-player-args"))c.extraPlayerArgs=e;c.allowfullscreen=a.hasAttribute("allowfullscreen");return c},I=function(a){if(-1!=(window.navigator&&window.navigator.userAgent||"").indexOf("Mobile")||!a.hasAttribute("autoplay"))return!1;a=String(a.getAttribute("autoplay")).toLowerCase();
return"none"!=a&&"false"!=a},J=function(a){var b=window.getComputedStyle(a).width;a=window.getComputedStyle(a).height;0===parseFloat(b)||isNaN(parseInt(b,10))?b="100%":-1==b.indexOf("%")&&(b=parseInt(b,10));0===parseFloat(a)||isNaN(parseInt(a,10))?a="100%":-1==a.indexOf("%")&&(a=parseInt(a,10));return{width:b,height:a}};E.prototype.K=function(){var a=this.h?this.querySelector("#"+this.h):null;if(a){var b=J(this);a.width=b.width;a.height=b.height}};
var K=function(a,b,c,d){a.a.addCueRange(b,c,d);a.J.push({id:b,start:String(c),end:String(d)})},L=function(a,b,c,d){for(var g=c/4,e=0,q=d.length;e<q;e++){var m=b+g*e,t=b+c;0===e?m+=.1:e===q-1&&--m;K(a,d[e],m,t)}},M=function(a,b,c){var d=parseInt(a.getAttribute("preview-duration"),10)||30;c&&b+d>c&&(d=c-b);L(a,b,d,["preview_q0","preview_q1","preview_q2","preview_q3","preview_q4"])};
E.prototype.O=function(){this.g=!0;var a=F(this).preview,b=this.a.getDuration();switch(a){case "none":case "standard":L(this,0,b,["q0","q1","q2","q3","q4"]);break;case "intro":case "preview":b?(a=F(this).startPosition,M(this,a&&a<b?a:0,b)):this.w=!0}this.hasAttribute("pause-on-end")&&K(this,"ending",b-1,b);this.a.addEventListener("seekto",function(){r("seekto",this)}.bind(this),!1);this.o=5;b=0;for(a=this.c.length;b<a;++b)switch(this.c[b].l){case 0:this.play();break;case 1:this.pause();break;case 2:this.seek(this.c[b].A);
break;case 3:this.toggleMute();break;case 4:this.setYouTubeId(this.c[b].A,this.c[b].R)}this.c=[]};
E.prototype.P=function(a){a=parseInt(a.data,10);if(!isNaN(a)){var b="";switch(a){case 0:b="ended";this.hasAttribute("loop")&&this.replay();break;case 1:b="playing";if(!this.B&&I(this))this.B=!0,this.w&&(M(this,this.a.getCurrentTime()),this.w=!1);else{var c=this.a;!c.isMuted()||this.hasAttribute("muted")||this.F||c.unMute();0==this.F&&(this.F=!0);0==this.o&&r("replayed",this);r("playpressed",this)}break;case 2:b="paused";break;case 3:b="buffering"}b&&r(b,this);this.o=a}};
E.prototype.M=function(a){"ending"==a.data?this.pause():this.a.removeCueRange(a.data);switch(a.data){case "q0":r("viewed0percent",this);break;case "q1":r("viewed25percent",this);break;case "q2":r("viewed50percent",this);break;case "q3":r("viewed75percent",this);break;case "q4":r("viewed100percent",this);break;case "preview_q0":r("previewed0percent",this);break;case "preview_q1":r("previewed25percent",this);break;case "preview_q2":r("previewed50percent",this);break;case "preview_q3":r("previewed75percent",
this);break;case "preview_q4":this.a.pauseVideo(),r("previewed100percent",this),this.removeAttribute("autoplay")}};document.registerElement("gwd-youtube",{prototype:E.prototype});}).call(this);