From 61c8b8a24f3280282581a72442ca8a4f56d25573 Mon Sep 17 00:00:00 2001 From: Nithin David <1277421+nithindavid@users.noreply.github.com> Date: Thu, 12 Aug 2021 23:17:11 +0530 Subject: [PATCH] Moves height calculation logic to Vue side --- app/javascript/sdk/IFrameHelper.js | 10 +++------- app/javascript/widget/App.vue | 6 ++++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/javascript/sdk/IFrameHelper.js b/app/javascript/sdk/IFrameHelper.js index eab8fc293..901ca5f77 100644 --- a/app/javascript/sdk/IFrameHelper.js +++ b/app/javascript/sdk/IFrameHelper.js @@ -183,16 +183,12 @@ export const IFrameHelper = { updateIframeHeight: message => { setTimeout(() => { const iframe = IFrameHelper.getAppFrame(); - const unreadMessageWrap = iframe.contentWindow.document.querySelector( - '.unread-messages' - ); - if (!unreadMessageWrap) return; const { extraHeight = 0 } = message; - let scrollableMessageHeight = - unreadMessageWrap.scrollHeight + extraHeight; + if (!extraHeight) return; + const updatedIframeHeight = message.isFixedHeight - ? `${scrollableMessageHeight}px` + ? `${extraHeight}px` : '100%'; iframe.setAttribute( 'style', diff --git a/app/javascript/widget/App.vue b/app/javascript/widget/App.vue index 6d7efaed0..0a5135759 100755 --- a/app/javascript/widget/App.vue +++ b/app/javascript/widget/App.vue @@ -274,11 +274,13 @@ export default { // This function calculates the extra space needed for the view to // accomodate the height of close button + height of // read messages button. So that scrollbar won't appear - + const unreadMessageWrap = document.querySelector('.unread-messages'); const unreadCloseWrap = document.querySelector('.close-unread-wrap'); const readViewWrap = document.querySelector('.open-read-view-wrap'); - let extraHeight = 0; + if (!unreadMessageWrap) return 0; + + let extraHeight = unreadMessageWrap.scrollHeight; if (unreadCloseWrap) extraHeight += unreadCloseWrap.scrollHeight; if (readViewWrap) extraHeight += readViewWrap.scrollHeight;