mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 03:27:52 +00:00
feat: widget opened and closed events (#11240)
Fixes #9272 --------- Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import { addClasses, removeClasses, toggleClass } from './DOMHelpers';
|
||||
import { IFrameHelper } from './IFrameHelper';
|
||||
import { isExpandedView } from './settingsHelper';
|
||||
import {
|
||||
CHATWOOT_CLOSED,
|
||||
CHATWOOT_OPENED,
|
||||
} from '../widget/constants/sdkEvents';
|
||||
import { dispatchWindowEvent } from 'shared/helpers/CustomEventHelper';
|
||||
|
||||
export const bubbleSVG =
|
||||
'M240.808 240.808H122.123C56.6994 240.808 3.45695 187.562 3.45695 122.122C3.45695 56.7031 56.6994 3.45697 122.124 3.45697C187.566 3.45697 240.808 56.7031 240.808 122.122V240.808Z';
|
||||
@@ -65,22 +70,30 @@ export const createBubbleHolder = hideMessageBubble => {
|
||||
body.appendChild(bubbleHolder);
|
||||
};
|
||||
|
||||
const handleBubbleToggle = newIsOpen => {
|
||||
IFrameHelper.events.onBubbleToggle(newIsOpen);
|
||||
|
||||
if (newIsOpen) {
|
||||
dispatchWindowEvent({ eventName: CHATWOOT_OPENED });
|
||||
} else {
|
||||
dispatchWindowEvent({ eventName: CHATWOOT_CLOSED });
|
||||
chatBubble.focus();
|
||||
}
|
||||
};
|
||||
|
||||
export const onBubbleClick = (props = {}) => {
|
||||
const { toggleValue } = props;
|
||||
const { isOpen } = window.$chatwoot;
|
||||
if (isOpen !== toggleValue) {
|
||||
const newIsOpen = toggleValue === undefined ? !isOpen : toggleValue;
|
||||
window.$chatwoot.isOpen = newIsOpen;
|
||||
if (isOpen === toggleValue) return;
|
||||
|
||||
toggleClass(chatBubble, 'woot--hide');
|
||||
toggleClass(closeBubble, 'woot--hide');
|
||||
toggleClass(widgetHolder, 'woot--hide');
|
||||
IFrameHelper.events.onBubbleToggle(newIsOpen);
|
||||
const newIsOpen = toggleValue === undefined ? !isOpen : toggleValue;
|
||||
window.$chatwoot.isOpen = newIsOpen;
|
||||
|
||||
if (!newIsOpen) {
|
||||
chatBubble.focus();
|
||||
}
|
||||
}
|
||||
toggleClass(chatBubble, 'woot--hide');
|
||||
toggleClass(closeBubble, 'woot--hide');
|
||||
toggleClass(widgetHolder, 'woot--hide');
|
||||
|
||||
handleBubbleToggle(newIsOpen);
|
||||
};
|
||||
|
||||
export const onClickChatBubble = () => {
|
||||
|
||||
Reference in New Issue
Block a user