Repository navigation
Expand file tree
/
Copy pathamp-youtube-0.1.js
More file actions
9 lines (9 loc) · 4.19 KB
/
Copy pathamp-youtube-0.1.js
File metadata and controls
9 lines (9 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
(window.AMP = window.AMP || []).push({n:"amp-youtube", f:(function(AMP) {var process={env:{NODE_ENV:"production"}};function l(b,a){function e(){}e.prototype=a.prototype;b.prototype=new e;b.prototype.constructor=b;for(var c in a)if(Object.defineProperties){var f=Object.getOwnPropertyDescriptor(a,c);f&&Object.defineProperty(b,c,f)}else b[c]=a[c]};(new Date).getTime();var m=self.log=self.log||{user:null,dev:null};function p(){if(m.user)return m.user;throw Error("failed to call initLogConstructor");};var q=Object.prototype.toString;function r(b){var a,e,c=a||function(b){return b},f=b.dataset;b=Object.create(null);var d=e?e:/^param(.+)/,h;for(h in f){var k=h.match(d);if(k){var g=k[1][0].toLowerCase()+k[1].substr(1);b[c(g)]=f[h]}}return b};function t(b,a){var e;if(!a)return b;var c=b.split("#",2),f=c[0].split("?",2),d=f[0]+(f[1]?e?"?"+a+"&"+f[1]:"?"+f[1]+"&"+a:"?"+a);return d+=c[1]?"#"+c[1]:""}function u(b){var a=[],e;for(e in b){var c=b[e];if(null!=c)if(Array.isArray(c))for(var f=0;f<c.length;f++){var d=c[f];a.push(encodeURIComponent(e)+"="+encodeURIComponent(d))}else f=c,a.push(encodeURIComponent(e)+"="+encodeURIComponent(f))}return a.join("&")};var w,x="Webkit webkit Moz moz ms O o".split(" ");function y(b,a){for(var e in a){var c=b,f=a[e],d;d=c.style;var h=e;w||(w=Object.create(null));var k=w[h];if(!k){k=h;if(void 0===d[h]){var g;g=h;g=g.charAt(0).toUpperCase()+g.slice(1);a:{for(var n=0;n<x.length;n++){var v=x[n]+g;if(void 0!==d[v]){g=v;break a}}g=""}void 0!==d[g]&&(k=g)}w[h]=k}(d=k)&&(c.style[d]=f)}};function z(b){AMP.BaseElement.call(this,b);this.g=0;this.f=this.c=this.a=this.b=null}l(z,AMP.BaseElement);z.prototype.preconnectCallback=function(b){this.preconnect.preload(A(this));this.preconnect.url("https://s.ytimg.com",b);this.preconnect.url("https://i.ytimg.com",b)};z.prototype.isLayoutSupported=function(b){return"fixed"==b||"fixed-height"==b||"responsive"==b||"fill"==b||"flex-item"==b};z.prototype.renderOutsideViewport=function(){return.75};
z.prototype.buildCallback=function(){this.b=p().assert(this.element.getAttribute("data-videoid"),"The data-videoid attribute is required for <amp-youtube> %s",this.element);this.getPlaceholder()||B(this)};function A(b){return"https://www.youtube.com/embed/"+encodeURIComponent(b.b||"")+"?enablejsapi=1"}
z.prototype.layoutCallback=function(){var b=this,a=this.element.ownerDocument.createElement("iframe"),e=A(this),c=r(this.element);"autoplay"in c&&(delete c.autoplay,p().warn("Autoplay is currently not support with amp-youtube."));e=t(e,u(c));a.setAttribute("frameborder","0");a.setAttribute("allowfullscreen","true");a.src=e;this.applyFillContent(a);this.element.appendChild(a);this.a=a;this.c=new Promise(function(a){b.f=a});this.win.addEventListener("message",function(a){var d=a;if("https://www.youtube.com"==
d.origin&&d.source==b.a.contentWindow&&d.data&&("[object Object]"===q.call(d.data)||0==d.data.indexOf("{"))){var c;if("[object Object]"===q.call(d.data))c=d.data;else a:{try{c=JSON.parse(d.data);break a}catch(e){}c=void 0}d=c;void 0!==d&&("onReady"==d.event?b.f(b.a):"infoDelivery"==d.event&&d.info&&void 0!==d.info.playerState&&(b.g=d.info.playerState))}});return this.loadPromise(a).then(function(){var a=b.win,a=a.__AMP_TOP||a;return(a.services&&a.services.timer&&a.services.timer.obj).promise(300)}).then(function(){b.a.contentWindow.postMessage(JSON.stringify({event:"listening"}),
"*")}).then(function(){return b.c})};z.prototype.pauseCallback=function(){this.a&&this.a.contentWindow&&1==this.g&&this.a.contentWindow.postMessage(JSON.stringify({event:"command",func:"pauseVideo",args:""}),"*")};
function B(b){var a=b.element.ownerDocument.createElement("img"),e=b.b||"";y(a,{"object-fit":"cover",visibility:"hidden"});a.src="https://i.ytimg.com/vi/"+encodeURIComponent(e)+"/sddefault.jpg#404_is_fine";a.setAttribute("placeholder","");a.setAttribute("referrerpolicy","origin");b.applyFillContent(a);b.element.appendChild(a);b.loadPromise(a).then(function(){if(120==a.naturalWidth&&90==a.naturalHeight)throw Error("sddefault.jpg is not found");}).catch(function(){a.src="https://i.ytimg.com/vi/"+encodeURIComponent(e)+
"/hqdefault.jpg";return b.loadPromise(a)}).then(function(){y(a,{visibility:""})})}AMP.registerElement("amp-youtube",z);
})});
//# sourceMappingURL=amp-youtube-0.1.js.map