Ignore Width Changes of the iframe, listen only to width changes.
This commit is contained in:
@@ -1,16 +1,26 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
let height = getCurrentHeight();
|
||||||
setupResizeListener();
|
setupResizeListener();
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
||||||
function setupResizeListener() {
|
function setupResizeListener() {
|
||||||
const RESIZE_CODE = 'resize:';
|
const resizeObserver = new ResizeObserver((entries) => setTimeout(handleHeightChange, 100));
|
||||||
|
|
||||||
const resizeObserver = new ResizeObserver(entries => {
|
|
||||||
const height = document.querySelector('body > main').scrollHeight;
|
|
||||||
window.parent.postMessage(RESIZE_CODE + JSON.stringify({height}), '*');
|
|
||||||
})
|
|
||||||
|
|
||||||
resizeObserver.observe(document.body);
|
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;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user