Skip to content
Snippets Groups Projects
Commit 237b2cf4 authored by Paal Joergensen's avatar Paal Joergensen
Browse files

HFP-2016/HFP-2282 Fix blinking CKEditor dialog

parent ea51e758
No related branches found
No related tags found
No related merge requests found
......@@ -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';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment