@newswire/frames
Version:
A minimalistic take on responsive iframes in the spirit of Pym.js.
3 lines (2 loc) • 2.14 kB
JavaScript
var n=/xPYMx/;function i(i){function t(t){if(t.source===i.contentWindow){var e=t.data;if("amp"===e.sentinel&&"embed-size"===e.type)i.setAttribute("height",e.height);else if("string"==typeof e&&"pym"===e.slice(0,3)){var a=e.split(n);"height"===a[2]&&i.setAttribute("height",a[3])}}}return window.addEventListener("message",t,!1),i.contentWindow&&i.contentWindow.postMessage({sentinel:"amp",type:"frames-init"},"*"),function(){window.removeEventListener("message",t,!1)}}function t(n,t){var e=void 0===t?{}:t,a=e.attributes,r=e.src,o=document.createElement("iframe"),f=i(o);if(r&&o.setAttribute("src",r),o.setAttribute("width","100%"),o.setAttribute("scrolling","no"),o.setAttribute("marginheight","0"),o.setAttribute("frameborder","0"),a)for(var u in a)o.setAttribute(u,a[u]);return n.appendChild(o),{remove:function(){f(),n.removeChild(o)}}}var e="data-frame-attribute-".length;function a(n){for(var i={},t=n.attributes,a=t.length,r=0;r<a;r++){var o=t[r].name;"data-frame-attribute-"===o.slice(0,e)&&(i[o.slice(e)]=t[r].value)}return i}function r(){for(var n=document.querySelectorAll("[data-frame-src]:not([data-frame-auto-initialized])"),i=0;i<n.length;i++){var e=n[i],r=e.getAttribute("data-frame-src"),o=a(e);e.setAttribute("data-frame-auto-initialized",""),t(e,{attributes:o,src:r})}}function o(n){void 0===n&&(n=document.documentElement.offsetHeight),window.parent.postMessage({sentinel:"amp",type:"embed-size",height:n},"*")}function f(){window.addEventListener("load",function n(){o(),window.removeEventListener("load",n,!1)},!1)}function u(){window.addEventListener("resize",function(){return o()},!1)}function d(){window.addEventListener("message",function n(i){var t=i.data;"amp"===t.sentinel&&"frames-init"===t.type&&(window.removeEventListener("message",n,!1),o())},!1)}function m(n){void 0===n&&(n=300),setInterval(o,n)}function c(){o(),f(),u(),d()}function s(n){c(),m(n)}export{t as Framer,r as autoInitFrames,c as initFrame,s as initFrameAndPoll,i as observeIframe,o as sendFrameHeight,d as sendHeightOnFramerInit,f as sendHeightOnLoad,m as sendHeightOnPoll,u as sendHeightOnResize};
//# sourceMappingURL=frames.module.js.map