From d1bbffce2ef0aeb77b787e920b940fe922412705 Mon Sep 17 00:00:00 2001 From: Roman Axelrod Date: Sun, 23 Oct 2022 18:43:44 +0300 Subject: [PATCH] Ignore Width Changes of the iframe, listen only to width changes. --- layouts/scripts/frame-index.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/layouts/scripts/frame-index.js b/layouts/scripts/frame-index.js index 79bb1a1..15843d2 100644 --- a/layouts/scripts/frame-index.js +++ b/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); +} - const resizeObserver = new ResizeObserver(entries => { - const height = document.querySelector('body > main').scrollHeight; - window.parent.postMessage(RESIZE_CODE + JSON.stringify({height}), '*'); - }) +function handleHeightChange(entries) { + const updatedHeight = getCurrentHeight(); + if (height === updatedHeight) { + return; + } - resizeObserver.observe(document.body); + const RESIZE_CODE = 'resize:'; + window.parent.postMessage(RESIZE_CODE + JSON.stringify({height}), '*'); + height = updatedHeight; +} + +function getCurrentHeight() { + return document.querySelector('body > main').scrollHeight; }