From 237b2cf4d4c49443706bae64e6335611da30f8e7 Mon Sep 17 00:00:00 2001 From: Paal Joergensen <pal.jorgensen@gmail.com> Date: Mon, 21 Jun 2021 15:33:46 +0200 Subject: [PATCH] HFP-2016/HFP-2282 Fix blinking CKEditor dialog --- scripts/h5peditor-editor.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/scripts/h5peditor-editor.js b/scripts/h5peditor-editor.js index ec5782ba..c37bd5a1 100644 --- a/scripts/h5peditor-editor.js +++ b/scripts/h5peditor-editor.js @@ -96,6 +96,15 @@ ns.Editor = function (library, defaultParams, replace, iframeLoaded) { $window.on('pagehide', action); }; + /** + * Object for keeping the scrollHeight + clientHeight used when the previous resize occurred + * This is used to skip handling resize when nothing actually is resized. + */ + const previousHeight = { + scroll: 0, + client: 0 + }; + /** * Checks if iframe needs resizing, and then resize it. * @@ -105,14 +114,24 @@ ns.Editor = function (library, defaultParams, replace, iframeLoaded) { if (!iframe.contentDocument || !iframe.contentDocument.body || self.preventResize) { return; // Prevent crashing when iframe is unloaded } - if (iframe.clientHeight === iframe.contentDocument.body.scrollHeight && - (iframe.contentDocument.body.scrollHeight === iframe.contentWindow.document.body.clientHeight || - iframe.contentDocument.body.scrollHeight - 1 === iframe.contentWindow.document.body.clientHeight || - iframe.contentDocument.body.scrollHeight === iframe.contentWindow.document.body.clientHeight - 1)) { + + // Has height changed? + const heightNotChanged = + previousHeight.scroll === iframe.contentDocument.body.scrollHeight && + previousHeight.client === iframe.contentWindow.document.body.clientHeight; + + if (heightNotChanged || ( + iframe.clientHeight === iframe.contentDocument.body.scrollHeight && + Math.abs(iframe.contentDocument.body.scrollHeight - iframe.contentWindow.document.body.clientHeight) <= 1 + )) { return; // Do not resize unless page and scrolling differs // Note: ScrollHeight may be 1px larger in some cases(Edge) where the actual height is a fraction. } + // Save the current scrollHeight/clientHeight + previousHeight.scroll = iframe.contentDocument.body.scrollHeight; + previousHeight.client = iframe.contentWindow.document.body.clientHeight; + // Retain parent size to avoid jumping/scrolling var parentHeight = iframe.parentElement.style.height; iframe.parentElement.style.height = iframe.parentElement.clientHeight + 'px'; -- GitLab