Browse Source

Ignore Width Changes of the iframe, listen only to width changes.

pull/1/head
Roman Axelrod 3 years ago
parent
commit
d1bbffce2e
  1. 20
      layouts/scripts/frame-index.js

20
layouts/scripts/frame-index.js

@ -1,16 +1,26 @@
'use strict';
let height = getCurrentHeight();
setupResizeListener();
///
function setupResizeListener() {
const RESIZE_CODE = 'resize:';
const resizeObserver = new ResizeObserver((entries) => setTimeout(handleHeightChange, 100));
resizeObserver.observe(document.body);
}
function handleHeightChange(entries) {
const updatedHeight = getCurrentHeight();
if (height === updatedHeight) {
return;
}
const resizeObserver = new ResizeObserver(entries => {
const height = document.querySelector('body > main').scrollHeight;
const RESIZE_CODE = 'resize:';
window.parent.postMessage(RESIZE_CODE + JSON.stringify({height}), '*');
})
height = updatedHeight;
}
resizeObserver.observe(document.body);
function getCurrentHeight() {
return document.querySelector('body > main').scrollHeight;
}

Loading…
Cancel
Save