From d9e61986f765f9c373e88293aaa0676bf405644e Mon Sep 17 00:00:00 2001 From: Thomas Hansen Date: Wed, 27 Sep 2023 19:30:26 +0300 Subject: [PATCH] Bug fix in inline mode --- .../system/openai/front.files/chat/default.js | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/backend/files/system/openai/front.files/chat/default.js b/backend/files/system/openai/front.files/chat/default.js index 67a331fbbf..d5badda4f9 100644 --- a/backend/files/system/openai/front.files/chat/default.js +++ b/backend/files/system/openai/front.files/chat/default.js @@ -161,21 +161,24 @@ function aista_create_chat_ui() { window.document.body.appendChild(aistaChatWnd); } - // Adding event listener to input field to allow for closing it with escape key. - const aistaChatInpField = document.getElementsByClassName('aista-chat-prompt')[0]; - aistaChatInpField.addEventListener('keydown', (e) => { - if (e.key === 'Escape') { - aistaChatWnd.style.display = 'none'; - const btns = window.document.getElementsByClassName('aista-chat-btn'); - if (btns.length > 0) { - btns[0].style.display = 'block'; - } - if (ainiro_con) { - ainiro_con.stop(); - ainiro_con = null; + if (!ainiroParentElement || ainiroParentElement === '') { + + // Adding event listener to input field to allow for closing it with escape key. + const aistaChatInpField = document.getElementsByClassName('aista-chat-prompt')[0]; + aistaChatInpField.addEventListener('keydown', (e) => { + if (e.key === 'Escape') { + aistaChatWnd.style.display = 'none'; + const btns = window.document.getElementsByClassName('aista-chat-btn'); + if (btns.length > 0) { + btns[0].style.display = 'block'; + } + if (ainiro_con) { + ainiro_con.stop(); + ainiro_con = null; + } } - } - }); + }); + } // Add an event listener to the close button. window.document.getElementsByClassName('aista-chat-close-btn')[0].addEventListener('click', () => {