2020-04-03 07:34:58 +00:00
|
|
|
import { addClass, toggleClass, wootOn } from './DOMHelpers';
|
2020-04-22 07:44:09 +00:00
|
|
|
import { IFrameHelper } from './IFrameHelper';
|
2020-08-09 10:37:32 +00:00
|
|
|
import { BUBBLE_DESIGN } from './constants';
|
2020-04-03 07:34:58 +00:00
|
|
|
|
|
|
|
export const bubbleImg =
|
|
|
|
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAUVBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////8IN+deAAAAGnRSTlMAAwgJEBk0TVheY2R5eo+ut8jb5OXs8fX2+cjRDTIAAADsSURBVHgBldZbkoMgFIThRgQv8SKKgGf/C51UnJqaRI30/9zfe+NQUQ3TvG7bOk9DVeCmshmj/CuOTYnrdBfkUOg0zlOtl9OWVuEk4+QyZ3DIevmSt/ioTvK1VH/s5bY3YdM9SBZ/mUUyWgx+U06ycgp7D8msxSvtc4HXL9BLdj2elSEfhBJAI0QNgJEBI1BEBsQClVBVGDgwYOLAhJkDM1YOrNg4sLFAsLJgZsHEgoEFFQt0JAFGFjQsKAMJ0LFAexKgZYFyJIDxJIBNJEDNAtSJBLCeBDCOBFAPzwFA94ED+zmhwDO9358r8ANtIsMXi7qVAwAAAABJRU5ErkJggg==';
|
|
|
|
|
|
|
|
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 getBubbleView = type =>
|
|
|
|
BUBBLE_DESIGN.includes(type) ? type : BUBBLE_DESIGN[0];
|
|
|
|
export const isExpandedView = type => getBubbleView(type) === BUBBLE_DESIGN[1];
|
|
|
|
|
|
|
|
export const setBubbleText = bubbleText => {
|
|
|
|
if (isExpandedView(window.$chatwoot.type)) {
|
|
|
|
const textNode = document.getElementById('woot-widget--expanded__text');
|
|
|
|
textNode.innerHTML = bubbleText;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-04-03 07:34:58 +00:00
|
|
|
export const createBubbleIcon = ({ className, src, target }) => {
|
2020-08-09 10:37:32 +00:00
|
|
|
let bubbleClassName = `${className} woot-elements--${window.$chatwoot.position}`;
|
2020-04-03 07:34:58 +00:00
|
|
|
const bubbleIcon = document.createElement('img');
|
|
|
|
bubbleIcon.src = src;
|
2020-09-04 13:43:22 +00:00
|
|
|
bubbleIcon.alt = 'bubble-icon';
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const createBubbleHolder = () => {
|
|
|
|
addClass(bubbleHolder, 'woot--bubble-holder');
|
|
|
|
body.appendChild(bubbleHolder);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const createNotificationBubble = () => {
|
|
|
|
addClass(notificationBubble, 'woot--notification');
|
|
|
|
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 = () => {
|
|
|
|
wootOn(bubbleHolder, 'click', onBubbleClick);
|
|
|
|
};
|