2022-10-12 21:42:06 +00:00
|
|
|
import { addClasses, removeClasses, toggleClass } from './DOMHelpers';
|
2020-04-22 07:44:09 +00:00
|
|
|
import { IFrameHelper } from './IFrameHelper';
|
2022-02-25 10:48:18 +00:00
|
|
|
import { isExpandedView } from './settingsHelper';
|
2020-04-03 07:34:58 +00:00
|
|
|
|
2022-12-14 23:21:20 +00:00
|
|
|
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';
|
2020-04-03 07:34:58 +00:00
|
|
|
|
|
|
|
export const body = document.getElementsByTagName('body')[0];
|
|
|
|
export const widgetHolder = document.createElement('div');
|
|
|
|
|
|
|
|
export const bubbleHolder = document.createElement('div');
|
2021-09-02 06:43:53 +00:00
|
|
|
export const chatBubble = document.createElement('button');
|
|
|
|
export const closeBubble = document.createElement('button');
|
2020-04-03 07:34:58 +00:00
|
|
|
export const notificationBubble = document.createElement('span');
|
|
|
|
|
2020-08-09 10:37:32 +00:00
|
|
|
export const setBubbleText = bubbleText => {
|
|
|
|
if (isExpandedView(window.$chatwoot.type)) {
|
|
|
|
const textNode = document.getElementById('woot-widget--expanded__text');
|
|
|
|
textNode.innerHTML = bubbleText;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-12-14 23:21:20 +00:00
|
|
|
export const createBubbleIcon = ({ className, path, target }) => {
|
2020-08-09 10:37:32 +00:00
|
|
|
let bubbleClassName = `${className} woot-elements--${window.$chatwoot.position}`;
|
2022-12-14 23:21:20 +00:00
|
|
|
const bubbleIcon = document.createElementNS(
|
|
|
|
'http://www.w3.org/2000/svg',
|
|
|
|
'svg'
|
|
|
|
);
|
|
|
|
bubbleIcon.setAttributeNS(null, 'id', 'woot-widget-bubble-icon');
|
|
|
|
bubbleIcon.setAttributeNS(null, 'width', '24');
|
|
|
|
bubbleIcon.setAttributeNS(null, 'height', '24');
|
|
|
|
bubbleIcon.setAttributeNS(null, 'viewBox', '0 0 240 240');
|
|
|
|
bubbleIcon.setAttributeNS(null, 'fill', 'none');
|
|
|
|
bubbleIcon.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
|
|
|
|
|
|
|
|
const bubblePath = document.createElementNS(
|
|
|
|
'http://www.w3.org/2000/svg',
|
|
|
|
'path'
|
|
|
|
);
|
|
|
|
bubblePath.setAttributeNS(null, 'd', path);
|
|
|
|
bubblePath.setAttributeNS(null, 'fill', '#FFFFFF');
|
|
|
|
|
|
|
|
bubbleIcon.appendChild(bubblePath);
|
2020-04-03 07:34:58 +00:00
|
|
|
target.appendChild(bubbleIcon);
|
2020-08-09 10:37:32 +00:00
|
|
|
|
|
|
|
if (isExpandedView(window.$chatwoot.type)) {
|
|
|
|
const textNode = document.createElement('div');
|
|
|
|
textNode.id = 'woot-widget--expanded__text';
|
|
|
|
textNode.innerHTML = '';
|
|
|
|
target.appendChild(textNode);
|
|
|
|
bubbleClassName += ' woot-widget--expanded';
|
|
|
|
}
|
|
|
|
|
|
|
|
target.className = bubbleClassName;
|
2020-04-03 07:34:58 +00:00
|
|
|
return target;
|
|
|
|
};
|
|
|
|
|
2022-05-06 14:00:48 +00:00
|
|
|
export const createBubbleHolder = hideMessageBubble => {
|
|
|
|
if (hideMessageBubble) {
|
2022-10-12 21:42:06 +00:00
|
|
|
addClasses(bubbleHolder, 'woot-hidden');
|
2022-05-06 14:00:48 +00:00
|
|
|
}
|
2022-10-12 21:42:06 +00:00
|
|
|
addClasses(bubbleHolder, 'woot--bubble-holder');
|
2020-04-03 07:34:58 +00:00
|
|
|
body.appendChild(bubbleHolder);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const createNotificationBubble = () => {
|
2022-10-12 21:42:06 +00:00
|
|
|
addClasses(notificationBubble, 'woot--notification');
|
2020-04-03 07:34:58 +00:00
|
|
|
return notificationBubble;
|
|
|
|
};
|
|
|
|
|
2020-07-07 18:34:44 +00:00
|
|
|
export const onBubbleClick = (props = {}) => {
|
|
|
|
const { toggleValue } = props;
|
|
|
|
const { isOpen } = window.$chatwoot;
|
|
|
|
if (isOpen !== toggleValue) {
|
|
|
|
const newIsOpen = toggleValue === undefined ? !isOpen : toggleValue;
|
|
|
|
window.$chatwoot.isOpen = newIsOpen;
|
|
|
|
|
|
|
|
toggleClass(chatBubble, 'woot--hide');
|
|
|
|
toggleClass(closeBubble, 'woot--hide');
|
|
|
|
toggleClass(widgetHolder, 'woot--hide');
|
|
|
|
IFrameHelper.events.onBubbleToggle(newIsOpen);
|
2021-09-02 06:43:53 +00:00
|
|
|
|
|
|
|
if (!newIsOpen) {
|
|
|
|
chatBubble.focus();
|
|
|
|
}
|
2020-04-22 07:44:09 +00:00
|
|
|
}
|
2020-04-03 07:34:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const onClickChatBubble = () => {
|
2022-10-12 21:42:06 +00:00
|
|
|
bubbleHolder.addEventListener('click', onBubbleClick);
|
2020-04-03 07:34:58 +00:00
|
|
|
};
|
2021-11-22 09:35:29 +00:00
|
|
|
|
|
|
|
export const addUnreadClass = () => {
|
|
|
|
const holderEl = document.querySelector('.woot-widget-holder');
|
2022-10-12 21:42:06 +00:00
|
|
|
addClasses(holderEl, 'has-unread-view');
|
2021-11-22 09:35:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const removeUnreadClass = () => {
|
|
|
|
const holderEl = document.querySelector('.woot-widget-holder');
|
2022-10-12 21:42:06 +00:00
|
|
|
removeClasses(holderEl, 'has-unread-view');
|
2021-11-22 09:35:29 +00:00
|
|
|
};
|