From b8ba947ba837fc4ca9bcb6252e716878eebf0cc7 Mon Sep 17 00:00:00 2001 From: Sr <39112652+Itswag@users.noreply.github.com> Date: Mon, 18 Sep 2023 21:27:08 +0800 Subject: [PATCH] feat: Added defaultOpen Attribute for iframe (#302) * feat: Added defaultOpen Attribute for iframe This commit introduces a new attribute `defaultOpen` for the iframe created in `iframe.js`. The `defaultOpen` attribute allows the iframe to be visible by default when the page loads. This new feature enhances the user experience by providing an option to display the chatbot window immediately after the page is loaded, without requiring user interaction. * Update iframe.js code standard --- client/public/js/iframe.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/client/public/js/iframe.js b/client/public/js/iframe.js index 3febabe11..08f1f6df6 100644 --- a/client/public/js/iframe.js +++ b/client/public/js/iframe.js @@ -4,7 +4,8 @@ async function embedChatbot() { const script = document.getElementById('fastgpt-iframe'); const botSrc = script?.getAttribute('data-src'); const primaryColor = script?.getAttribute('data-color') || '#4e83fd'; - + const defaultOpen = script?.getAttribute('data-default-open') === 'true'; + if (!botSrc) { console.error(`Can't find appid`); return; @@ -30,10 +31,10 @@ async function embedChatbot() { iframe.title = 'FastGPT Chat Window'; iframe.id = chatWindowId; iframe.src = botSrc; - iframe.style.cssText = - 'visibility: hidden; border: none; position: fixed; flex-direction: column; justify-content: space-between; box-shadow: rgba(150, 150, 150, 0.2) 0px 10px 30px 0px, rgba(150, 150, 150, 0.2) 0px 0px 0px 1px; bottom: 4rem; right: 1rem; width: 24rem; height: 40rem; max-width: 90vw; max-height: 85vh; border-radius: 0.75rem; display: flex; z-index: 2147483647; overflow: hidden; left: unset; background-color: #F3F4F6;'; - + 'border: none; position: fixed; flex-direction: column; justify-content: space-between; box-shadow: rgba(150, 150, 150, 0.2) 0px 10px 30px 0px, rgba(150, 150, 150, 0.2) 0px 0px 0px 1px; bottom: 4rem; right: 1rem; width: 24rem; height: 40rem; max-width: 90vw; max-height: 85vh; border-radius: 0.75rem; display: flex; z-index: 2147483647; overflow: hidden; left: unset; background-color: #F3F4F6;'; + iframe.style.visibility = defaultOpen ? 'unset' : 'hidden'; + document.body.appendChild(iframe); let chatBtnDragged = false;