@flourish/sdk
Version:
The Flourish SDK
3 lines (2 loc) • 3.53 kB
JavaScript
!function(){"use strict";var t,a;function s(){if(null==t){var e=function(){var e=window.location;"about:srcdoc"==e.href&&(e=window.parent.location);var i={};return function(e,t,n){for(;n=t.exec(e);)i[decodeURIComponent(n[1])]=decodeURIComponent(n[2])}(e.search.substring(1).replace(/\+/g,"%20"),/([^&=]+)=?([^&]*)/g),i}();t="referrer"in e?/^https:\/\/medium.com\//.test(e.referrer):!("auto"in e)}return t}function d(e){var t=e||window.innerWidth;return 999<t?650:599<t?575:400}function u(e,t){if(window.top!==window.self){var n=window;if("srcdoc"==n.location.pathname&&(n=n.parent),a)return e=parseInt(e,10),void n.parent.postMessage({sentinel:"amp",type:"embed-size",height:e},"*");var i={sender:"Flourish",context:"iframe.resize",method:"resize",height:e,src:n.location.toString()};if(t)for(var o in t)i[o]=t[o];n.parent.postMessage(JSON.stringify(i),"*")}}function h(){return(-1!==navigator.userAgent.indexOf("Safari")||-1!==navigator.userAgent.indexOf("iPhone"))&&-1==navigator.userAgent.indexOf("Chrome")}function c(o){window.addEventListener("message",function(t){if(null!=t.source&&(t.origin===document.location.origin||t.origin.match(/\/\/localhost:\d+$|\/\/flourish-api\.com$|\.flourish\.(?:local(:\d+)?|net|rocks|studio)$/))){var e;try{e=JSON.parse(t.data)}catch(e){return void console.warn("Unexpected non-JSON message: "+JSON.stringify(t.data))}if("Flourish"===e.sender){for(var n=document.querySelectorAll("iframe"),i=0;i<n.length;i++)if(n[i].contentWindow==t.source||n[i].contentWindow==t.source.parent)return void o(e,n[i]);console.warn("could not find frame",e)}}}),h()&&(window.addEventListener("resize",e),e())}function e(){for(var e=document.querySelectorAll(".flourish-embed"),t=0;t<e.length;t++){var n=e[t];if(!n.getAttribute("data-width")){var i=n.querySelector("iframe"),o=window.getComputedStyle(n),r=n.offsetWidth-parseFloat(o.paddingLeft)-parseFloat(o.paddingRight);i.style.width=r+"px"}}}function l(e,t,n,i){n&&"number"==typeof n&&(n+="px"),i&&"number"==typeof i&&(i+="px"),i||(e.match(/\?/)?e+="&auto=1":e+="?auto=1",i=d(n)+"px");var o=document.createElement("iframe");return o.setAttribute("scrolling","no"),o.setAttribute("frameborder","0"),o.setAttribute("src",e),t.appendChild(o),n?o.style.width=n:h()?o.style.width=t.offsetWidth+"px":o.style.width="100%",i&&("%"===i.charAt(i.length-1)&&(i=parseFloat(i)/100*t.parentNode.offsetHeight+"px"),o.style.height=i),o}!function(){Flourish.warn=function(e){console.warn(e)};var t,n=window.top===window.self,i=n?null:(a="#amp=1"==window.location.hash,{createEmbedIframe:l,isFixedHeight:s,getHeightForBreakpoint:d,startEventListeners:c,notifyParentWindow:u,isSafari:h}),o=!0;function r(){var e;Flourish.fixed_height||(null!=t?e=t:o&&(e=i.getHeightForBreakpoint()),e!==window.innerHeight&&i.notifyParentWindow(e))}function e(){r(),window.addEventListener("resize",r)}Flourish.uploadImage=function(e){if(n||"story_editor"!==Flourish.environment)throw"Invalid upload request";var t={sender:"Flourish",method:"request-upload",name:e.name,accept:e.accept};window.parent.postMessage(JSON.stringify(t),"*")},Flourish.setHeight=function(e){Flourish.fixed_height||(o=null==(t=e),r())},Flourish.checkHeight=function(){if(!n){var e=Flourish.__container_height;null!=e?(Flourish.fixed_height=!0,i.notifyParentWindow(e)):i.isFixedHeight()?Flourish.fixed_height=!0:(Flourish.fixed_height=!1,r())}},Flourish.fixed_height=n||i.isFixedHeight(),"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e):e()}()}();
//# sourceMappingURL=embedded.js.map