'use strict'; /*globals document, console, XMLHttpRequest*/ function polyfill() { if (typeof Object.assign !== 'function') { // Must be writable: true, enumerable: false, configurable: true Object.defineProperty(Object, "assign", { value: function assign(target, varArgs) { // .length of function is 2 'use strict'; if (target == null) { // TypeError if undefined or null throw new TypeError('Cannot convert undefined or null to object'); } var to = Object(target); for (var index = 1; index < arguments.length; index++) { var nextSource = arguments[index]; if (nextSource != null) { // Skip over if undefined or null for (var nextKey in nextSource) { // Avoid bugs when hasOwnProperty is shadowed if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) { to[nextKey] = nextSource[nextKey]; } } } } return to; }, writable: true, configurable: true }); } } polyfill(); (function (window, document, elemTag, srcUrl, r, a, m) { a = document.createElement(elemTag); m = document.getElementsByTagName(elemTag)[0]; a.async = 1; a.src = srcUrl; m.parentNode.insertBefore(a, m); })(window, document, 'script', 'https://www.googletagmanager.com/gtag/js?id=UA-115538286-1'); window.dataLayer = window.dataLayer || []; // (function (window, document, elemTag, srcUrl, r, a, m) { // a = document.createElement(elemTag); // m = document.getElementsByTagName(elemTag)[0]; // a.async = 1; // a.src = srcUrl; // m.parentNode.insertBefore(a, m); // })(window, document, 'script', '//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'); // // (window.adsbygoogle = window.adsbygoogle || []).push({ // google_ad_client: "ca-pub-1287965589478199", // enable_page_level_ads: true // }); (function () { var DEBUG = true; var serverHost = 'https://app.wabi-app.com'; var lang = 'en'; var phoneNumber = '+3197005034841'; var position = 'left'; var gaId = 'UA-115538286-1'; var Util = { isMobile: function () { return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)); }, addResetCss: function () { var cssId = 'wabiCss'; // you could encode the css path itself to generate id.. if (!document.getElementById(cssId)) { var head = document.getElementsByTagName('head')[0]; var link = document.createElement('link'); link.id = cssId; link.rel = 'stylesheet'; link.type = 'text/css'; link.href = 'https://cdnjs.cloudflare.com/ajax/libs/yui/3.18.1/cssnormalize-context/cssnormalize-context-min.css'; link.media = 'all'; head.appendChild(link); } } }; function init() { Util.addResetCss(); var wabiWidgets = document.querySelectorAll('.wabi-chat-widget'); if (wabiWidgets && wabiWidgets.length > 0) { return; } var wabiElem = document.createElement('div'); wabiElem.setAttribute('class', 'wabi-chat-widget yui3-normalized'); wabiElem.style.width = 'unset'; wabiElem.style.minWidth = '0'; inflateWabiWidget(wabiElem); document.body.appendChild(wabiElem); } function inflateWabiWidget(wabiWidget) { window.addEventListener('message', function (e) { var command = e.data && e.data.command; if (command === 'wabi_toggle_window') { if (screen.width < (420 + 32)) { wabiWindow.style.width = Math.max(screen.width - 32, 340) + "px"; } // if (isMobile() && !phoneNumber) { // if client didnt provide us phone number and its mobile, we need higher height to accomodate the .. // wabiWindow.style.height = "360px"; // } var label = e.data.source; if (wabiWindow.style.opacity === '0') { logEvent('window_show', { event_category: 'widget', event_label: label }); wabiWindow.style.display = 'inline'; setTimeout(function () { wabiWindow.style.opacity = "1"; }, 0); } else { logEvent('window_hide', { event_category: 'widget', event_label: label }); wabiWindow.style.opacity = "0"; setTimeout(function () { wabiWindow.style.display = 'none'; }, 100); } } else if (command === 'wabi_window_ready') { for (var i = 0; i < this.frames.length; i++) { var frame = this.frames[i]; frame.postMessage('wabi_window_ready', '*'); } } else if (command === 'wabi_show_button') { wabiButton.style.display = 'inline'; } else if (command === 'open_wabi_website') { var utmMedium = window.location.hostname; window.open('https://www.wabi-app.com/?utm_source=wabi-widget&utm_medium=' + utmMedium + '&utm_campaign=powered-by', '_blank'); } }); var innerElem = document.createElement('div'); // innerElem.style.border = 'none'; // innerElem.style.overflow = 'hidden'; // innerElem.style.background = 'none'; // innerElem.style.bottom = "18px"; // var right = isMobile() ? "4px" : "18px"; // innerElem.style.right = right; // innerElem.style.display = "inline"; // innerElem.style.padding = "0px"; // innerElem.style.position = "fixed"; // innerElem.style.top = "auto"; // innerElem.style.height = "100px"; // innerElem.style.width = "100px"; innerElem.style.zIndex = "2147483646"; innerElem.setAttribute('class', 'yui3-normalized'); var wabiButton = createWidgetButton(innerElem); wabiButton.setAttribute('class', 'yui3-normalized'); var wabiWindow = createWidgetWindow(innerElem); wabiWindow.setAttribute('class', 'yui3-normalized'); wabiWidget.appendChild(innerElem); wabiWidget.setAttribute('data-wabi-inflated', 'true'); } function createWidgetButton(wabiWidget) { var iframe = document.createElement('iframe'); var scriptUrl = serverHost + '/widget/button?phone_number=' + phoneNumber; if (lang) { scriptUrl += '&lang=' + lang; } if (window.location.hostname) { scriptUrl += '&host=' + encodeURIComponent(window.location.hostname); } iframe.setAttribute('id', 'wabi-floating-button'); iframe.setAttribute('src', scriptUrl); iframe.setAttribute('width', '80px'); iframe.setAttribute('frameborder', '0'); iframe.setAttribute('allowtransparency', 'true'); iframe.setAttribute('allowfullscreen', 'true'); iframe.setAttribute('scrolling', 'no'); iframe.style.height = "80px"; iframe.style.width = "80px"; iframe.style.border = 'none'; iframe.style.overflow = 'hidden'; iframe.style.background = 'none'; iframe.style.display = "none"; iframe.style.padding = "0px"; iframe.style.bottom = "18px"; var margin = Util.isMobile() ? "4px" : "18px"; if (position === 'left') { iframe.style.left = margin; } else { iframe.style.right = margin; } iframe.style.position = "fixed"; iframe.style.top = "auto"; iframe.style.zIndex = "2147483646"; wabiWidget.appendChild(iframe); return iframe; } function createWidgetWindow(wabiWidget) { var isMobile = Util.isMobile(); var iframe = document.createElement('iframe'); var scriptUrl = serverHost + '/widget/window?phone_number=' + phoneNumber; if (lang) { scriptUrl += '&lang=' + lang; } iframe.setAttribute('id', 'wabi-window'); iframe.setAttribute('src', scriptUrl); iframe.setAttribute('width', '80px'); iframe.setAttribute('frameborder', '0'); iframe.setAttribute('allowtransparency', 'true'); iframe.setAttribute('allowfullscreen', 'true'); iframe.setAttribute('scrolling', 'no'); iframe.style.border = 'none'; iframe.style.overflow = 'hidden'; iframe.style.background = 'white'; iframe.style.borderRadius = '9pt'; iframe.style.bottom = "128px"; var margin = isMobile ? "14px" : "28px"; if (position === 'left') { iframe.style.left = margin; } else { iframe.style.right = margin; } iframe.style.boxShadow = "rgba(0, 0, 0, 0.15) 0px 3pt 12pt"; iframe.style.width = "440px"; // min 340px if (lang === 'de') { // temp fix - need more space for de iframe.style.height = isMobile ? "370px" : "360px"; } else { iframe.style.height = isMobile ? "360px" : "330px"; } iframe.style.display = "none"; iframe.style.opacity = '0'; // if (DEBUG) { // iframe.style.opacity = '1'; // iframe.style.display = "inline"; // } iframe.style.transition = 'opacity 0.1s linear, height 0.1s linear, width 0.1s linear'; iframe.style.padding = "0px"; iframe.style.position = "fixed"; iframe.style.top = "auto"; iframe.style.zIndex = "2147483646"; wabiWidget.appendChild(iframe); return iframe; } function logEvent(action, options) { // console.log('ga.event, action=' + action + ', options=' + (options ? JSON.stringify(options) : options)); var opts = options || {}; Object.assign(opts, { 'send_to': gaId }); wabi_gtag('event', action, opts); } function initGA() { wabi_gtag('js', new Date()); wabi_gtag('config', gaId); window.addEventListener('message', function (e) { var command = e.data && e.data.command; if (command === 'log_event') { var action = e.data.action; if (!action) { return; } logEvent(action, e.data.options); } }); } function wabi_gtag() { window.dataLayer.push(arguments); } initGA(); init(); }());