fix: Use exisiting bubble nodes if available (#2026)

This commit is contained in:
Pranav Raj S 2021-04-02 15:04:16 +05:30 committed by GitHub
parent bf8f19b334
commit 1b99ab3098
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -23,6 +23,11 @@ export const IFrameHelper = {
return `${baseUrl}/widget?website_token=${websiteToken}`;
},
createFrame: ({ baseUrl, websiteToken }) => {
if (IFrameHelper.getAppFrame()) {
return;
}
loadCSS();
const iframe = document.createElement('iframe');
const cwCookie = Cookies.get('cw_conversation');
let widgetUrl = IFrameHelper.getUrl({ baseUrl, websiteToken });
@ -47,6 +52,7 @@ export const IFrameHelper = {
IFrameHelper.preventDefaultScroll();
},
getAppFrame: () => document.getElementById('chatwoot_live_chat_widget'),
getBubbleHolder: () => document.getElementsByClassName('woot--bubble-holder'),
sendMessage: (key, value) => {
const element = IFrameHelper.getAppFrame();
element.contentWindow.postMessage(
@ -166,7 +172,10 @@ export const IFrameHelper = {
iframe.style.visibility = '';
iframe.setAttribute('id', `chatwoot_live_chat_widget`);
loadCSS();
if (IFrameHelper.getBubbleHolder().length) {
return;
}
createBubbleHolder();
if (!window.$chatwoot.hideMessageBubble) {