You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
612 B
26 lines
612 B
'use strict';
|
|
|
|
let height = getCurrentHeight();
|
|
setupResizeListener();
|
|
|
|
///
|
|
|
|
function setupResizeListener() {
|
|
const resizeObserver = new ResizeObserver((entries) => setTimeout(handleHeightChange, 100));
|
|
resizeObserver.observe(document.body);
|
|
}
|
|
|
|
function handleHeightChange(entries) {
|
|
const updatedHeight = getCurrentHeight();
|
|
if (height === updatedHeight) {
|
|
return;
|
|
}
|
|
|
|
const RESIZE_CODE = 'resize:';
|
|
window.parent.postMessage(RESIZE_CODE + JSON.stringify({height}), '*');
|
|
height = updatedHeight;
|
|
}
|
|
|
|
function getCurrentHeight() {
|
|
return document.querySelector('body > main').scrollHeight;
|
|
}
|
|
|