// (c) Shmooze ( https://www.shmooze.io ), Afaan Bilal ( https://afaanbilal.github.io )
// Ouibounce
!function(e,n){"function"==typeof define&&define.amd?define(n):"object"==typeof exports?module.exports=n(require,exports,module):e.ouibounce=n()}(this,function(e,n,o){return function(e,n){"use strict";function o(e,n){return"undefined"==typeof e?n:e}function i(e){var n=24*e*60*60*1e3,o=new Date;return o.setTime(o.getTime()+n),"; expires="+o.toUTCString()}function t(){s()||(L.addEventListener("mouseleave",u),L.addEventListener("mouseenter",r),L.addEventListener("keydown",c))}function u(e){e.clientY>k||(D=setTimeout(m,y))}function r(){D&&(clearTimeout(D),D=null)}function c(e){g||e.metaKey&&76===e.keyCode&&(g=!0,D=setTimeout(m,y))}function d(e,n){return a()[e]===n}function a(){for(var e=document.cookie.split("; "),n={},o=e.length-1;o>=0;o--){var i=e[o].split("=");n[i[0]]=i[1]}return n}function s(){return d(T,"true")&&!v}function m(){s()||(e&&(e.style.display="block"),E(),f())}function f(e){var n=e||{};"undefined"!=typeof n.cookieExpire&&(b=i(n.cookieExpire)),n.sitewide===!0&&(w=";path=/"),"undefined"!=typeof n.cookieDomain&&(x=";domain="+n.cookieDomain),"undefined"!=typeof n.cookieName&&(T=n.cookieName),document.cookie=T+"=true"+b+x+w,L.removeEventListener("mouseleave",u),L.removeEventListener("mouseenter",r),L.removeEventListener("keydown",c)}var l=n||{},v=l.aggressive||!1,k=o(l.sensitivity,20),p=o(l.timer,1e3),y=o(l.delay,0),E=l.callback||function(){},b=i(l.cookieExpire)||"",x=l.cookieDomain?";domain="+l.cookieDomain:"",T=l.cookieName?l.cookieName:"viewedOuibounceModal",w=l.sitewide===!0?";path=/":"",D=null,L=document.documentElement;setTimeout(t,p);var g=!1;return{fire:m,disable:f,isDisabled:s}}});
// Data to QueryString
function toQS(a,b){var d,e,c=[];for(var f in a)a.hasOwnProperty(f)&&(d=~f.indexOf("[")?b?b+"["+f.substring(0,f.indexOf("["))+"]"+f.substring(f.indexOf("[")):f:b?b+"["+f+"]":f,e=a[f],c.push("object"==typeof e?toQS(e,d):encodeURIComponent(d)+"="+encodeURIComponent(e)));return c.join("&")}
window.mobileAndTabletCheck = function() { let check = false; (function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check = true;})(navigator.userAgent||navigator.vendor||window.opera); return check; };
(function(){
this.ShmoozeWidget = function(){
var match = document.cookie.match(new RegExp('(^| )' + 'dontShowShmoozeWidget' + '=([^;]+)'));
if (match) {
// return;
}
this.options = {};
this.container = null;
this.titleContainer = null;
this.button = null;
this.icon_open = null;
this.icon_close = null;
this.main = null;
this.openContainer = null;
this.openTitlebar = null;
this.isOpen = false;
// fix for safari on iOS
this.hasEverOpened = false;
this.frame = null;
var defaults = {
removeBtnMinimizes: false,
bubbleOnDesktop: false,
position: 'r',
buttonColor: '#00ccff',
showButton: true,
showBubble: true,
logoIcon: "https://app.shmooze.io/assets/widget-v2/icon-open.svg",
logoImage: "https://app.shmooze.io/assets/widget-v2/icon-open.svg",
title: "Connect with PHSU",
titleFont: "'Segoe UI', Tahoma, Geneva, Verdana, sans-serif",
titleFontSize: 20,
titleColor: '#000',
titlebarHeight: 40,
titlebarColor: '#fff',
googleFont: '',
width: 400,
height: 435,
redirect: '',
postBack: false,
logoImg: '',
pop: false, // {wait: 10, onunload: true}
showAt: 'always',
bounceOnOut: true,
conversation_id: 564
}
if (arguments[0] && typeof arguments[0] == "object") {
this.options = extendDefaults(defaults, arguments[0]);
} else {
this.options = defaults;
}
// Check for show timings
if (this.options.showAt !== 'always') {
if (
this.options.showAt.hasOwnProperty('from')
&& this.options.showAt.hasOwnProperty('to')
) {
var fromHour = this.options.showAt.from;
var toHour = this.options.showAt.to;
var currentHour = (new Date()).getHours();
if (currentHour < fromHour || currentHour > toHour) {
console.log('Shmooze: Widget not in showtime.')
return;
}
}
}
// Add css
document.getElementsByTagName('head')[0].innerHTML += '';
if (this.options.titleFont == 'CUSTOM') {
document.getElementsByTagName('head')[0].innerHTML += '';
this.options.titleFont = "'" + this.options.googleFont + "'";
}
//Creates the main container
var docFrag = document.createDocumentFragment();
var shmoozeContainer = document.createElement('div');
shmoozeContainer.className = 'shmooze-widget';
shmoozeContainer.style.width = (this.options.width + 50) + "px";
var shmoozeClosedContainer = document.createElement('div');
shmoozeClosedContainer.className = 'shmooze-closed-container';
var titleArea = document.createElement('div');
titleArea.className = 'shmooze-title-area';
titleArea.style.backgroundColor = this.options.titlebarColor;
var logoImage = document.createElement('img');
logoImage.src = this.options.logoImage;
logoImage.className = 'shmooze-logo-image';
logoImage.setAttribute('alt', 'Logo');
titleArea.appendChild(logoImage);
var titleText = document.createElement('p');
titleText.textContent = this.options.title;
titleText.className = 'shmooze-title-text';
titleText.style.padding = "10px";
titleText.style.fontSize = this.options.titleFontSize + "px";
titleText.style.fontFamily = this.options.titleFont;
titleText.style.color = this.options.titleColor;
titleArea.appendChild(titleText);
var _this = this;
titleArea.addEventListener("click", function() {
_this.toggle();
});
shmoozeClosedContainer.appendChild(titleArea);
var shmoozeButton = document.createElement('div');
shmoozeButton.className = 'shmooze-btn';
shmoozeButton.style.backgroundColor = this.options.buttonColor;
shmoozeButton.addEventListener("click", function() {
_this.toggle();
});
var btnIcon_open = document.createElement('img');
btnIcon_open.src = this.options.logoIcon;
btnIcon_open.className = 'shmooze-btn-icon shmooze-btn-icon_open';
btnIcon_open.setAttribute('alt', 'Open');
shmoozeButton.appendChild(btnIcon_open);
var btnIcon_close = document.createElement('img');
btnIcon_close.src = "https://app.shmooze.io/assets/widget-v2/icon-close.svg";
btnIcon_close.className = 'shmooze-btn-icon shmooze-btn-icon_close transparent';
btnIcon_close.setAttribute('alt', 'Close');
shmoozeButton.appendChild(btnIcon_close)
shmoozeClosedContainer.appendChild(shmoozeButton);
shmoozeContainer.appendChild(shmoozeClosedContainer);
var shmoozeOpenContainer = document.createElement('div');
shmoozeOpenContainer.className = 'shmooze-open-container';
shmoozeOpenContainer.style.width = this.options.width + "px";
shmoozeOpenContainer.style.height = "0px";
shmoozeOpenContainer.style.opacity = "0";
var shmoozeOpenTitlebar = document.createElement('div');
shmoozeOpenTitlebar.className = 'shmooze-open-titlebar';
shmoozeOpenTitlebar.style.backgroundColor = this.options.titlebarColor;
shmoozeOpenTitlebar.style.height = this.options.titlebarHeight + "px";
var openLogoImage = document.createElement('img');
openLogoImage.src = this.options.logoImage;
openLogoImage.className = 'shmooze-open-logo-image';
openLogoImage.setAttribute('alt', 'Logo');
shmoozeOpenTitlebar.appendChild(openLogoImage);
var removeButton = document.createElement('a');
removeButton.className = 'shmooze-remove-btn';
removeButton.addEventListener("click", function() {
if (_this.options.removeBtnMinimizes) {
_this.toggle();
} else {
_this.remove();
}
});
removeButton.title = "Close";
shmoozeOpenTitlebar.appendChild(removeButton);
var expandButton = document.createElement('a');
expandButton.className = 'shmooze-expand-btn';
expandButton.href = "https://app.shmooze.io/converse/c/" + this.options.conversation_id;
expandButton.target = "_blank";
expandButton.title = "Expand";
shmoozeOpenTitlebar.appendChild(expandButton);
var openTitleText = document.createElement('p');
openTitleText.textContent = this.options.title;
openTitleText.className = 'shmooze-title-text';
openTitleText.style.fontSize = this.options.titleFontSize + "px";
openTitleText.style.fontFamily = this.options.titleFont;
openTitleText.style.color = this.options.titleColor;
shmoozeOpenTitlebar.appendChild(openTitleText);
shmoozeOpenContainer.appendChild(shmoozeOpenTitlebar);
var shmoozeMain = document.createElement('div');
shmoozeMain.className = 'shmooze-main';
shmoozeMain.style.height = "calc(100% - " + this.options.titlebarHeight + "px)";
var shmoozeFrame = document.createElement('iframe');
shmoozeFrame.className = 'shmooze-frame';
shmoozeFrame.scrolling = 'no';
shmoozeFrame.frameborder = '0';
shmoozeFrame.src = "https://app.shmooze.io/converse/c/" + this.options.conversation_id + "?embed&chat&np&w2" + ((this.options.postBack) ? "&postBack" : "");
shmoozeMain.appendChild(shmoozeFrame);
shmoozeOpenContainer.appendChild(shmoozeMain);
shmoozeContainer.appendChild(shmoozeOpenContainer);
if (this.options.bubbleOnDesktop) {
if (mobileAndTabletCheck()) {
this.options.showBubble = false
this.options.showButton = true
} else {
this.options.showBubble = true
this.options.showButton = false
}
}
if (!this.options.showButton) {
shmoozeButton.style.display = "none";
shmoozeClosedContainer.style.minHeight = "100px";
}
if (!this.options.showBubble) {
titleArea.style.display = "none";
}
// Widget Position
switch (this.options.position) {
case 'l':
shmoozeContainer.style.left = "0";
shmoozeClosedContainer.style.left = "0";
shmoozeButton.style.left = "30px";
shmoozeOpenContainer.style.left = "20px";
break;
case 'r':
default:
shmoozeContainer.style.right = "0";
shmoozeClosedContainer.style.right = "0";
shmoozeButton.style.right = "30px";
shmoozeOpenContainer.style.right = "20px";
break;
}
// Set widget to full-with on devices widths <= 480px
if (matchMedia) {
const mq = window.matchMedia("(max-width: 480px)");
var _st = this;
onWidthChange = function(mq) {
if (mq.matches) {
switch (_st.options.position) {
case 'r':
shmoozeOpenContainer.style.right = "0";
break;
case 'l':
shmoozeOpenContainer.style.left = "0";
break;
}
} else {
switch (_st.options.position) {
case 'r':
shmoozeOpenContainer.style.right = "20px";
break;
case 'l':
shmoozeOpenContainer.style.left = "20px";
break;
}
}
}
mq.addListener(onWidthChange);
onWidthChange(mq);
}
docFrag.appendChild(shmoozeContainer);
document.body.appendChild(docFrag);
this.container = shmoozeContainer;
this.button = shmoozeButton;
this.main = shmoozeMain;
this.openContainer = shmoozeOpenContainer;
this.openTitlebar = shmoozeOpenTitlebar;
this.icon_open = btnIcon_open;
this.icon_close = btnIcon_close;
this.titleContainer = titleArea;
this.frame = shmoozeFrame;
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var eventer = window[eventMethod];
eventer(eventMethod=="attachEvent" ? "onmessage" : "message", function(e) {
if (e.origin != "https://app.shmooze.io" && e.origin != "http://localhost") {
console.log("Unauthorized Origin: " + e.origin + " blocked.");
return;
}
var key = e.message ? "message" : "data";
var data = JSON.parse(e[key]);
if (data.hasOwnProperty('get_origin_url')) {
shmoozeFrame.contentWindow.postMessage('{"original_url": "' + window.location.href + '"}', '*');
return;
}
if (data.hasOwnProperty("redirect")) {
if (!data.redirect.hasOwnProperty('type')) return;
if (!data.redirect.hasOwnProperty('url')) return;
if (data.redirect.type == 'i') {
window.location = data.redirect.url;
return;
}
if (data.redirect.type == 'w') {
if (!data.redirect.hasOwnProperty('wait_seconds')) return;
setTimeout(function() {
window.location = data.redirect.url;
},
parseInt(data.redirect.wait_seconds) * 1000);
}
return;
}
if (_this.options.pop.onunload) window.onbeforeunload = null;
if (_this.options.redirect != '')
window.location = _this.options.redirect +
(data.hasOwnProperty("formData") ?
(((_this.options.redirect.indexOf("?")>=0) ? '&' : '?' ) + toQS(data.formData))
: '' );
}, false);
// ouibounce
if (this.options.bounceOnOut) {
ouibounce(false, {
aggressive: true,
cookieName: 'shmoozeWv2Expanded',
callback: function() {
_this.open();
//console.log('ouibounce fired!');
}
});
}
if (this.options.pop) {
if (this.options.pop.wait > 0) {
var popUpTimer = setTimeout(function() {
_this.open();
clearTimeout(popUpTimer);
}, _this.options.pop.wait * 1000);
}
if (_this.options.pop.onunload) {
window.onbeforeunload = function(event) {
_this.open();
var message = 'Lets have a conversation before you go?';
event = event || window.event;
event.preventDefault = true;
event.cancelBubble = true;
event.returnValue = message;
return message;
};
}
}
}
//---------- Public methods ---------------
/**
* Open
*/
this.ShmoozeWidget.prototype.open = function(){
if (!this.isOpen) {
this.icon_open.className = 'shmooze-btn-icon shmooze-btn-icon_open transparent';
this.icon_close.className = 'shmooze-btn-icon shmooze-btn-icon_close';
if (this.options.showButton)
this.titleContainer.style.opacity = "0";
var _t = this;
setTimeout(function(){
_t.openContainer.style.height = (_t.options.height + _t.options.titlebarHeight) + "px";
_t.openTitlebar.style.display = 'block';
_t.openContainer.style.opacity = "1";
// iframe iOS fix
if (!_t.hasEverOpened) {
_t.frame.src = _t.frame.src;
_t.hasEverOpened = true;
}
}, (_t.options.showButton && _t.options.showBubble) ? 200 : 0);
}
this.isOpen = true;
}
/**
* Close
*/
this.ShmoozeWidget.prototype.close = function(){
if (this.isOpen) {
this.openContainer.style.opacity = "0";
this.openTitlebar.style.display = 'none';
this.icon_open.className = 'shmooze-btn-icon shmooze-btn-icon_open';
this.icon_close.className = 'shmooze-btn-icon shmooze-btn-icon_close transparent';
var _t = this;
setTimeout(function(){
_t.openContainer.style.height = "0px";
if (_t.options.showButton)
_t.titleContainer.style.opacity = "1";
}, 200);
}
this.isOpen = false;
}
/**
* Toggle
*/
this.ShmoozeWidget.prototype.toggle = function(){
if (this.isOpen) {
this.close();
} else {
this.open();
}
}
/**
* Remove
*/
this.ShmoozeWidget.prototype.remove = function(){
if (this.container) {
this.container.remove();
this.container = null;
// 1 Day cookie to preserve close state
var date = new Date();
date.setTime(date.getTime() + (1 * 24 * 60 * 60 * 1000));
document.cookie = "dontShowShmoozeWidget=true; expires=" + date.toGMTString() + "; path=/";
}
}
//---------- Private methods ---------------
/**
* Fill in missing options
*/
function extendDefaults(source, destination){
for (property in destination) {
if (destination.hasOwnProperty(property)) {
source[property] = destination[property];
}
}
return source;
}
})();
(function() {
if (typeof define === 'function' && define.amd)
define('ShmoozeWidget', function () { return ShmoozeWidget; });
else if (typeof module !== 'undefined' && module.exports)
module.exports = Notyf;
else
window.ShmoozeWidget = ShmoozeWidget;
})();