All files / libs iframeSize.ts

81.81% Statements 9/11
57.14% Branches 4/7
100% Functions 1/1
81.81% Lines 9/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24  1x 1x       1x     1x       1x   1x 1x   1x 1x        
function iframeSize(wrapperSelector: string): void {
  const wrapperEl = document.querySelector(wrapperSelector);
  Iif (!wrapperEl) {
    return;
  }
 
  const iframe = wrapperEl.querySelector("iframe") as HTMLIFrameElement;
 
  // asciinema is a snowflake, so treat it as such
  Iif (!iframe || (iframe.name && iframe.name.indexOf("asciicast") !== -1)) {
    return;
  }
 
  const IFRAME_RATIO = parseInt(iframe.width) / parseInt(iframe.height);
 
  const width = wrapperEl.getBoundingClientRect().width;
  const height = width / IFRAME_RATIO;
 
  iframe.width = width.toString();
  iframe.height = height.toString();
}
 
export default iframeSize;