/**
* Overriding localStorage functions, to use widget_id in key
*/
window.ccrp = window.ccrp || {
cleanBaseUrl: 'https://uc-widget.realpageuc.com',
baseUrl: 'https://uc-widget.realpageuc.com/',
csrfToken: 'CiHXDHLddNSXogCB9JH7ah9zBcT66GRd5aqbIeX2',
pusherKey: '',
contactPresenceChannel: 'contactPresenceChannel',
userPresenceChannel: 'userPresenceChannel',
ipAddr: "10.42.238.134",
url_rpservers: "https:\/\/uc-widget.realpageuc.com\/analytics\/clickstream",
google_analytics_enabled: null,
debug: false
};
window.ccrp.widgetSettings = {"widget":{"id":"cyOa6zBBBKpFFuTJi4Yow","active":true,"property_id":"3316982","company_name":"Dodson Property Management","terms_of_use_url":"https:\/\/www.realpage.com\/privacy-policy","terms_of_use_text":false,"name":"Hopper Lofts","title":"Need Help?","splash_screen_active":true,"splash_screen_greeting":"","privacy_policy_url":"https:\/\/www.realpage.com\/privacy-policy","privacy_policy_text":"Privacy","communication_modes":["chat"],"color_background":"#000000","color_secondary_background":"#40454F","color_text":"#FFFFFF","logo":"","logo_active":"","default_communication_mode":"chat","is_template":false,"multi_subject_label":"How can we help you?","transcript_enabled":false,"post_conversation_survey":true},"proactive":{"active":true,"include_mobile":false,"mobile_position":"left","desktop_position":"left","trigger_time":30,"headline_text":"Chat Invitation","invitation_text":"Have questions about living at Hopper Lofts? Chat with a live person right now about our community.","photo_link":"https:\/\/omnichannel-prod.s3.amazonaws.com\/default_images\/default_photo_link.jpg","icon_link":"","logo_link":"","logo_blurb_text":"","proactive_chat_format":["photo"],"chat_button_text":"Click to chat","color_text":"#40454F","color_primary":"#000000","color_background":"#FEFEFE","color_chat_button_text":"#FEFEFE"},"cta":{"title":"Need Help?","mobile_position":"br","desktop_position":"br","color_text":"#FFFFFF","color_background":"#000000","isMobile":false},"subjects":{"leasingsales":{"label":"Let's talk about renting an apartment","email_address":"","call_phone_number":"","text_phone_number":"","questions":[{"text":"Home Size","input_name":null,"type":"select","choices":["Studio","1","2","3+"],"required":false,"disclaimer":null},{"text":"Move-In Date","input_name":null,"type":"date","choices":false,"required":false,"disclaimer":null},{"text":"Pets","input_name":null,"type":"select","choices":["Yes","No"],"required":false,"disclaimer":null}],"modes":["chat"]}},"property":{"id":"3316982","email_address":"","property_name":"Hopper Lofts","call_phone_number":"","text_phone_number":""},"common_questions":{"email":true,"firstName":true,"lastName":true,"behalfOf":false,"phone":true,"emailRequired":true,"firstNameRequired":true,"lastNameRequired":true,"behalfOfRequired":false,"phoneRequired":false},"page_animations_enabled":true};
Storage.prototype._setItem = Storage.prototype.setItem;
Storage.prototype.setItem = function (key, value, override) {
if (typeof override == "undefined") {
override = false;
}
if (override) {
key = window.ccrp.widgetSettings.widget.id + '_' + key;
}
this._setItem(key, value);
};
Storage.prototype._getItem = Storage.prototype.getItem;
Storage.prototype.getItem = function (key, override) {
if (typeof override == "undefined") {
override = false;
}
if (override) {
key = window.ccrp.widgetSettings.widget.id + '_' + key;
}
return this._getItem(key);
};
Storage.prototype._removeItem = Storage.prototype.removeItem;
Storage.prototype.removeItem = function (key, override) {
if (typeof override == "undefined") {
override = false;
}
if (override) {
key = window.ccrp.widgetSettings.widget.id + '_' + key;
}
return this._removeItem(key);
};
if (typeof window.localStorage == 'undefined' || typeof window.sessionStorage == 'undefined') (function () {
var Storage = function (type) {
function createCookie(name, value, days) {
var date, expires;
if (days) {
date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
} else {
expires = "";
}
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=",
ca = document.cookie.split(';'),
i, c;
for (i=0; i < ca.length; i++) {
c = ca[i];
while (c.charAt(0)==' ') {
c = c.substring(1,c.length);
}
if (c.indexOf(nameEQ) == 0) {
return c.substring(nameEQ.length,c.length);
}
}
return null;
}
function setData(data) {
data = JSON.stringify(data);
if (type == 'session') {
window.name = data;
} else {
createCookie('localStorage', data, 365);
}
}
function clearData() {
if (type == 'session') {
window.name = '';
} else {
createCookie('localStorage', '', 365);
}
}
function getData() {
var data = type == 'session' ? window.name : readCookie('localStorage');
return data ? JSON.parse(data) : {};
}
// initialise if there's already data
var data = getData();
return {
length: 0,
clear: function () {
data = {};
this.length = 0;
clearData();
},
getItem: function (key) {
return data[key] === undefined ? null : data[key];
},
key: function (i) {
// not perfect, but works
var ctr = 0;
for (var k in data) {
if (ctr == i) return k;
else ctr++;
}
return null;
},
removeItem: function (key) {
delete data[key];
this.length--;
setData(data);
},
setItem: function (key, value) {
data[key] = value+''; // forces the value to a string
this.length++;
setData(data);
}
};
};
if (typeof window.localStorage == 'undefined') window.localStorage = new Storage('local');
if (typeof window.sessionStorage == 'undefined') window.sessionStorage = new Storage('session');
})();
window.rp = window.rp || {};
window.rp.widget = {
showWidget: true,
debug: false,
supportsLocalStorage: function() {
try {
if('localStorage' in window && window['localStorage'] !== null) {
if (typeof window.localStorage === 'object') {
try {
window.localStorage.setItem('localStorage', 1, true);
window.localStorage.removeItem('localStorage', true);
} catch (e) {
Storage.prototype._setItem = Storage.prototype.setItem;
Storage.prototype.setItem = function() {};
return false;
}
}
return true;
}
} catch (e) {
return false;
}
},
log: function() {
var args = arguments;
if (window.rp.widget.debug && window.console) {
for (var i = 0; i < args.length; i++){
console.log(args[i]);
}
}
},
addEvent: function (elem, event, fn) {
// avoid memory overhead of new anonymous functions for every event handler that's installed
// by using local functions
function listenHandler(e) {
var ret = fn.apply(this, arguments);
if (ret === false) {
e.stopPropagation();
e.preventDefault();
}
return(ret);
}
function attachHandler() {
// set the this pointer same as addEventListener when fn is called
// and make sure the event is passed to the fn also so that works the same too
var ret = fn.call(elem, window.event);
if (ret === false) {
window.event.returnValue = false;
window.event.cancelBubble = true;
}
return(ret);
}
if (elem.addEventListener) {
elem.addEventListener(event, listenHandler, false);
return {elem: elem, handler: listenHandler, event: event};
} else {
elem.attachEvent("on" + event, attachHandler);
return {elem: elem, handler: attachHandler, event: event};
}
}
}
// Check for IE version 9 and older
if (document.all && !window.atob) {
window.rp.widget.showWidget = false;
}
if (window.rp.widget.showWidget) {
//Append the window styles
var style = document.createElement('link');
style.media = "all";
style.type = "text/css";
style.rel = "stylesheet";
style.href = "https://uc-widget.realpageuc.com/build/assets/css/rpucWidgetWindow-56072b0f8e.css";
style.id = 'rpucStyles';
document.getElementsByTagName('head')[0].appendChild(style);
//Create the chat widget
window.rp.widget.addEvent(window, "load", function(e) {
var widget = document.createElement('div'),
windowHeight = window.innerHeight,
windowWidth = window.innerWidth,
isMobile = false;
widget.innerHTML =
'
'
function setAttributes(el, arrayOfTuples) {
var i = arrayOfTuples.length;
for(i; i--;) {
var tuple = arrayOfTuples[i];
el.setAttribute(tuple[0], tuple[1]);
}
};
function getPosition(isMobileDev){
var ctaSettings = window.ccrp.widgetSettings.cta,
pos = isMobileDev ? ctaSettings.mobile_position : ctaSettings.desktop_position;
if ( pos === true || typeof(pos) === 'undefined' ) {
if ( isMobileDev ){
pos = "rc";
} else {
pos = "br";
}
}
return pos;
}
function createCtaContainer (ctaClass, clrFl){
var ctaContainer = document.createElement('div');
setAttributes(ctaContainer, [
['id','cta-container'],
['class', 'always-ontop'],
['style','']
])
if (ctaClass != undefined) {
ctaContainer.classList.add( ctaClass );
} else {
ctaContainer.style.display = 'none';
}
ctaContainer.style.background = clrFl;
ctaContainer.addEventListener('click',function(e){
e.preventDefault();
e.stopPropagation();
window.parent.postMessage({event_name: 'widgetCtaClicked'}, '*');
})
return ctaContainer;
}
function createCtaContentElm(position, clrFl){
var ctaButtonWrapper = document.createElement('div');
var color_text = "#FFFFFF";
var title = "Need Help?";
// console.log('color_text')
ctaButtonWrapper.classList.add('cta-button-wrapper');
ctaButtonWrapper.style.borderBottom = "2px solid " + clrFl;
ctaButtonWrapper.innerHTML = '' +
'' +
'';
return ctaButtonWrapper;
}
var height, ctaContainer, width,
ctaPosition = getPosition(isMobile),
clrFl = window.ccrp.widgetSettings.widget.color_background,
ctaClass = {
"br": "rpuc-widget-live-comm-container-bottom",
"rc": "rpuc-widget-live-comm-container-right",
"tc": "rpuc-widget-live-comm-container-top"
};
// set position id
ctaClass = ctaClass[ctaPosition];
ctaContainer = createCtaContainer(ctaClass, clrFl);
ctaContainer.appendChild( createCtaContentElm(ctaPosition, clrFl) );
document.body.appendChild(ctaContainer);
document.body.appendChild(widget);
if (ctaPosition) {
window.rp.widget.ctaElm = document.querySelector("." + ctaClass);
} else {
window.rp.widget.ctaElm = null;
}
// height = '51px';
// window.parent.postMessage({event_name: 'widgetCtaHeight', params: {height: height}}, '*');
// window.postMessage({event_name: 'widgetCtaWidth', params: {width: ctaContainer.offsetWidth }}, '*');
// reset proactive chat
var currentURL = window.location.hostname;
var communicationIframe = document.getElementById('communicationIframe').contentWindow;
var proactiveWindow = document.getElementById('proactiveIframe')
var proactiveChatIframe = document.getElementById('proactiveIframe');
if ( proactiveChatIframe ) {
proactiveChatIframe = proactiveChatIframe.contentWindow;
}
window.onresize = function(_ev) {
communicationIframe.postMessage({event_name: 'modifyModalHeaderOnWindowResize', params: {parentWindowWidth: document.documentElement.clientWidth}}, '*');
};
window.onfocus = function() {
communicationIframe.postMessage({event_name: 'windowFocus', params: {focus: true}}, '*');
if (window.localStorage.getItem(currentURL + 'numShowProactiveChat', true) < maxNumShowProactiveChatModal && idleSecondsTimer == null) {
idleSecondsTimer = window.setTimeout(checkIdleTime, 1000);
}
}
window.onmousemove = function() {
if (window.localStorage.getItem(currentURL + 'numShowProactiveChat', true) < maxNumShowProactiveChatModal && idleSecondsTimer == null) {
idleSecondsTimer = window.setTimeout(checkIdleTime, 1000);
}
}
window.onmousewheel = function() {
if (window.localStorage.getItem(currentURL + 'numShowProactiveChat', true) < maxNumShowProactiveChatModal && idleSecondsTimer == null) {
idleSecondsTimer = window.setTimeout(checkIdleTime, 1000);
}
}
window.onblur = function() {
communicationIframe.postMessage({event_name: 'windowFocus', params: {focus: false}}, '*');
}
//Start showing proactive chat modal when user has gone idle
var ccrpWidgetSettings = window.ccrp.widgetSettings;
var widgetSettings = ccrpWidgetSettings.widget;
var widgetCtaSettings = ccrpWidgetSettings.cta;
var widgetCommonQuestionSettings = ccrpWidgetSettings.common_questions;
var widgetProactiveSettings = ccrpWidgetSettings.proactive;
var widgetPropertySettings = ccrpWidgetSettings.property;
var widgetSubjectSettings = ccrpWidgetSettings.subjects;
var idleTimeout = 30 ; // show proctive chat after this # seconds
var idleSecondsTimer = null;
var idleSecondsCounter = 0;
var maxNumShowProactiveChatModal = 1; //max number of times to show proactive chat question modal
var proactiveBackground = document.getElementById('rpucProactiveChatBackground');
window.rp.widget.log('currentURL: ' + currentURL);
// position is left, right, or center
var proactivePosition = "left";
var proactiveAvailable = true;
// inflection point decides which proactive chat flyout to show
var proactiveChatMobileInflectionPoint = 549;
var selectorsToOpenWidget = widgetCtaSettings.custom_triggers ? widgetCtaSettings.custom_triggers : false;
/* Assuming custom trigger object should look like this:
widgetSettings.cta.custom_triggers = {
elementID : someValue - OR - {
type: string,
bindModeStrict: boolean,
}
}
*/
window.rp.widget.log('widgetSettings: ', widgetSettings);
window.rp.widget.log('custom_triggers: ' + selectorsToOpenWidget);
if (typeof selectorsToOpenWidget == 'object') {
Object.keys(selectorsToOpenWidget).map(function(objectKey, index) {
var oneSelector = document.querySelectorAll(objectKey);
if (oneSelector.length > 0) {
var modalType, bindModeStrict = false;
if (typeof selectorsToOpenWidget[objectKey] == 'object') {
modalType = selectorsToOpenWidget[objectKey].type;
if (selectorsToOpenWidget[objectKey].bindModeStrict == true) {
bindModeStrict = true;
}
} else {
modalType = selectorsToOpenWidget[objectKey];
bindModeStrict = false;
}
for (var j = 0; j < oneSelector.length; j++) {
var elem = oneSelector[j];
if (bindModeStrict == true && modalType != 'undefined') {
var clone = oneSelector[j].cloneNode(true);
clone.removeAttribute('onclick');
clone.removeAttribute('onmouseup');
clone.removeAttribute('onmousedown');
oneSelector[j].parentNode.replaceChild(clone, oneSelector[j]);
elem = clone;
}
elem.addEventListener('click', function(_ev) {
if (modalType != 'undefined') {
_ev.preventDefault();
_ev.stopPropagation();
window.postMessage({event_name: 'showWidget', params: {type: modalType}}, '*');
}
});
}
}
});
}
if (typeof widgetProactiveSettings == 'object' && typeof widgetProactiveSettings.trigger_time === 'number') {
idleTimeout = widgetProactiveSettings.trigger_time;
}
if (window.rp.widget.supportsLocalStorage()) {
if (!window.localStorage.getItem(currentURL + 'window.localStorageExpires', true)) {
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth();
var day = date.getDate();
window.localStorage.setItem(currentURL + 'window.localStorageExpires', new Date(year + 1, month, day), true)
} else {
if (new Date() > window.localStorage.getItem(currentURL + 'window.localStorageExpires', true)) {
window.localStorage.clear();
}
}
//set number of times proactive chat is shown to 0
if (!window.localStorage.getItem(currentURL + 'numShowProactiveChat', true) || isNaN(window.localStorage.getItem(currentURL + 'numShowProactiveChat', true))) {
window.localStorage.setItem(currentURL + 'numShowProactiveChat', 0, true);
}
if (!window.localStorage.getItem('idleSecondsCounter', true) || isNaN(window.localStorage.getItem('idleSecondsCounter', true))) {
window.localStorage.setItem('idleSecondsCounter', 0, true);
} else {
idleSecondsCounter = window.localStorage.getItem('idleSecondsCounter', true);
}
}
function checkIdleTime() {
window.rp.widget.log('Check Idle Timer is running', proactiveAvailable)
if (window.rp.widget.supportsLocalStorage()) {
idleSecondsCounter++;
// if the chat widget isn't open, the timer is less than timeout, and proactive chat hasn't been shown before
if ( proactiveAvailable
&& idleTimeout > 0
&& idleSecondsCounter >= idleTimeout
&& document.querySelector('.rpucIframeHolder').style.display == 'none'
&& window.localStorage.getItem(currentURL + 'numShowProactiveChat', true) < maxNumShowProactiveChatModal
&& window.localStorage.getItem('widgetCommunicationChatInitialized', true) !== true
&& !window.localStorage.getItem('interactedWithWidget', true)) {
window.localStorage.setItem(currentURL + 'numShowProactiveChat', parseInt( window.localStorage.getItem(currentURL + 'numShowProactiveChat', true) ) + 1, true );
showProactiveChat();
idleSecondsCounter = 0;
} else {
idleSecondsTimer = window.setTimeout(checkIdleTime, 1000);
}
if(window.localStorage.getItem(currentURL + 'numShowProactiveChat', true) == maxNumShowProactiveChatModal || proactiveAvailable === false ) {
window.rp.widget.log('clearing timeout')
window.clearTimeout(idleSecondsTimer);
}
}
}
function showPopupWidget() {
document.querySelector('.rpucIframeHolder').classList.remove('docked');
document.querySelector('.rpucIframeHolder').classList.add('popUp');
document.querySelector('.rpucIframeHolder').style.display = 'block';
if (typeof proactiveWindow != "undefined" && proactiveWindow) {
hideProactiveChat();
// Do we need to post this event? - will this event be used for more than opening/closing docked/popup widget?
// window.postMessage({event_name: 'proactiveChat', params: {start: false}}, '*');
}
communicationIframe.postMessage({event_name: 'ShowPopupWidget', params: {parentWindowWidth: document.documentElement.clientWidth}}, '*');
if (window.rp.widget.supportsLocalStorage()) {
communicationIframe.postMessage({event_name: 'iframeSetLocalstorage', params: {name: 'widgetCommunicationIsOpened', value: true}}, '*');
window.localStorage.setItem('interactedWithWidget', true, true);
window.localStorage.setItem('ucWidgetUnreadMessages', 0, true);
window.postMessage({event_name: 'ucWidgetUnreadMessages', count: 0}, '*');
}
}
// show the main chat widget
function showDockedWidget(reinitialized) {
var iPhone = /iPhone/.test(navigator.userAgent),
iPad = /iPad/.test(navigator.userAgent),
android = /Android/.test(navigator.userAgent),
ctaContainer = document.querySelector('[class*="rpuc-widget-live-comm-container-"]'),
fallbackCtaContainerSelector = window.parent.document.querySelector('[class*="rpuc-widget-live-comm-container-"]'),
rpucIframeHolderContainer = document.querySelector('.rpucIframeHolder');
// console.log('documentElement', document);
// console.log('SHOW DOCKED WIDGET - ', ctaContainer);
// console.log('fallbackCtaContainerSelector', fallbackCtaContainerSelector);
rpucIframeHolderContainer.classList.remove('popUp');
rpucIframeHolderContainer.classList.add('docked');
rpucIframeHolderContainer.style.display = 'block';
if (iPhone || iPad){
window.rp.widget.log('is iPhone or iPad');
document.querySelector('body').style.setProperty('position', 'fixed');
$('body').on('touchstart', function(){
if ( rpucIframeHolderContainer.style.display === 'block' && document.body.style.position === 'fixed'){
document.querySelector('body').style.setProperty('position', 'static');
}
})
$('body').on('click',function(){
if ( rpucIframeHolderContainer.style.display === 'block' && document.body.style.position === 'fixed'){
document.querySelector('body').style.setProperty('position', 'static');
}
})
}
if (typeof proactiveWindow != "undefined" && proactiveWindow) {
hideProactiveChat();
// window.postMessage({event_name: 'proactiveChat', params: {start: false}}, '*');
}
if ( ctaContainer ) {
ctaContainer.style.setProperty('display','none');
} else if ( fallbackCtaContainerSelector ) {
// through testing, if this causes problems - this was a separate if statment
fallbackCtaContainerSelector.style.setProperty('display','none');
}
if (!reinitialized) {
communicationIframe.postMessage({event_name: 'ShowDockedWidget', params: {parentWindowWidth: document.documentElement.clientWidth}}, '*');
}
if (window.rp.widget.supportsLocalStorage()) {
communicationIframe.postMessage({event_name: 'iframeSetLocalstorage', params: {name: 'widgetCommunicationIsOpened', value: true}}, '*');
window.localStorage.setItem('interactedWithWidget', true, true);
window.localStorage.setItem('ucWidgetUnreadMessages', 0, true);
window.postMessage({event_name: 'ucWidgetUnreadMessages', count: 0}, '*');
}
}
function hideWidget() {
var iPhone = /iPhone/.test(navigator.userAgent),
iPad = /iPad/.test(navigator.userAgent),
ctaContainer = document.querySelector('[class*="rpuc-widget-live-comm-container-"]'),
fallbackCtaContainerSelector = window.parent.document.querySelector('[class*="rpuc-widget-live-comm-container-"]'),
rpucIframeHolderContainer = document.querySelector('.rpucIframeHolder');
rpucIframeHolderContainer.style.display = 'none';
if (iPhone || iPad){
window.rp.widget.log('document - removing blur listener');
document.querySelector('body').style.setProperty('position', 'static');
}
if ( ctaContainer ) {
ctaContainer.style.setProperty('display','block');
} else if ( fallbackCtaContainerSelector ) {
// through testing, if this causes problems - this was a separate if statment
fallbackCtaContainerSelector.style.setProperty('display','block');
}
if (window.rp.widget.supportsLocalStorage()) {
communicationIframe.postMessage({event_name: 'iframeSetLocalstorage', params: {name: 'widgetCommunicationIsOpened', value: false}}, '*');
}
}
function closeWidget() {
hideWidget();
if (communicationIframe && window.rp.widget.supportsLocalStorage() && !window.localStorage.getItem('widgetCommunicationChatInitialized', true)
&& window.ccrp.widgetSettings.widget.splash_screen_active === true) {
communicationIframe.postMessage({event_name: 'resetToSplash'}, '*');
}
window.clearTimeout(idleSecondsTimer);
/* some other logic */
}
function showProactiveChat() {
var pChatOffset;
var pChat = window.ccrp.widgetSettings.proactive;
var pChatFormat = pChat.proactive_chat_format;
var isMobile = false;
var logoVar = false;
var iconVar = false;
var photoVar = false;
var ctaContainer = document.getElementById("cta-container");
//var ctaContainer = document.querySelector('[class*="rpuc-widget-live-comm-container-"]');
//var fallbackCtaContainerSelector = window.parent.document.querySelector('[class*="rpuc-widget-live-comm-container-"]');
if ( typeof pChat !== 'object' ){
console.warn('Proactive chat settings object does not exist.');
return;
}
if ( isMobile && pChat.include_mobile == false) {
return;
}
// check for mobile
if ( isMobile ){
proactivePosition = 'center';
/* IMPORTANT: the way this widget is set up currently, it is absolutely necessary for the timer to wait a while to send this message
- ie. widgetSettings.data.attributes.cta.proactive_chat.trigger must be long enough.
If it is not, the lister won't be set up on the pChat widget and .postMessage won't work
TODO: alternative is to set up a 'minumum' on the front end by setting an interval to check if the listener is set or fire off the message until it sticks
*/
// minimum height of the proactive window in mobile
//set this to 230px if no logo
// proactiveWindow.style.setProperty('height','255px');
// add values based on formats
for (var i = 0; i < pChatFormat.length; i++){
var pChatVal = pChatFormat[i];
if ( pChatVal === 'logo'){
logoVar = true;
} else if ( pChatVal === 'icon' ){
iconVar = true;
} else if ( pChatVal === 'photo' ){
photoVar = true;
}
}
if ( logoVar === false ){
if ( iconVar === false ){
proactiveWindow.style.setProperty('min-height', '255px');
proactiveWindow.style.setProperty('height','255px');
} else {
proactiveWindow.style.setProperty('min-height', '255px');
proactiveWindow.style.setProperty('height','255px');
}
} else {
if ( iconVar ){
proactiveWindow.style.setProperty('height','360px');
} else {
proactiveWindow.style.setProperty('height','325px');
}
}
proactiveChatIframe.postMessage({event_name: 'showProactiveChatMobile', logo: logoVar, icon: iconVar },'*');
communicationIframe.postMessage({event_name: 'showProactiveChatMobile'}, '*');
//set width here to be at max-width, the inflection point
proactiveWindow.style.setProperty('max-width', proactiveChatMobileInflectionPoint + 'px');
proactiveWindow.style.setProperty('width','100%');
proactiveWindow.style.setProperty('top','0');
proactiveBackground.classList.add('active');
} else {
// this covers conditions that are not mobile OR are mobile & less than inflection point
if ( proactivePosition === 'center'){
proactiveBackground.classList.add('active');
}
for (var i = 0; i < pChatFormat.length; i++){
var pChatVal = pChatFormat[i];
if ( pChatVal === 'logo' ){
logoVar = true;
} else if ( pChatVal === 'icon' ){
iconVar = true;
} else if ( pChatVal === 'photo' ){
photoVar = true;
}
}
if ( logoVar ){
proactiveWindow.style.setProperty('height', '350px');
}
if ( iconVar === false && photoVar === false ){
proactiveWindow.style.setProperty('width', '549px');
}
proactiveChatIframe.postMessage({event_name: 'showProactiveChatFull', logo: logoVar, icon: iconVar, photo: photoVar },'*');
communicationIframe.postMessage({event_name: 'showProactiveChatFull'}, '*');
}
// show pChat after everything else is done
proactiveWindow.style.setProperty('display','block');
pChatOffset = proactiveWindow.offsetTop + proactiveWindow.clientHeight;
// hide cta if proactive chat is overlapping it
if ( pChatOffset > ctaContainer.offsetTop || pChatOffset > ctaContainer.getBoundingClientRect().top ){
ctaContainer.style.display = "none";
}
}
function hideProactiveChat(){
if (proactiveBackground) {
proactiveBackground.classList.remove('active');
}
if (proactiveWindow) {
proactiveWindow.style.setProperty('display','none');
}
}
// check for dropdown length
if ( document.getElementsByClassName('rpuc-widget-desktop-dropdown').length ) {
document.querySelector('.rpuc-widget-desktop-dropdown').onmouseover = function() {
document.querySelector('.rpuc-widget-desktop-dropdown').classList.remove('collapsed');
};
document.querySelector('.rpuc-widget-desktop-dropdown').onmouseleave = function() {
document.querySelector('.rpuc-widget-desktop-dropdown').classList.add('collapsed');
};
}
window.addEventListener("message", processEvents, false);
function processEvents(_ev) {
switch(_ev.data.event_name){
case 'androidFocusInResize':
var top = document.querySelector('.rpucIframeHolder.docked').getBoundingClientRect().top;
var height = $('.rpucIframeHolder').height();
if ( height < 530){
communicationIframe.postMessage({
event_name: 'androidModifyFooterAndComNav',
action:'hide'
}, '*');
}
break;
case 'androidFocusOutResize':
communicationIframe.postMessage({
event_name: 'androidModifyFooterAndComNav',
action:'show'
}, '*');
break;
case 'setBodyToFixed':
// if widget is open and the body style is set to static (or not fixed), make it fixed
if ( document.querySelector('.rpucIframeHolder').style.display === 'block' && document.body.style.position !== 'fixed'){
document.querySelector('body').style.setProperty('position', 'fixed');
}
break;
case 'leftRpucWidgetCtaClicked':
case 'rightRpucWidgetCtaClicked':
case 'bottomRpucWidgetCtaClicked':
case 'widgetCtaClicked':
showDockedWidget(_ev.data.reinitialized);
break;
case 'resetInactivity':
// End showing questions modal when user is gone idle
idleSecondsCounter = 0;
break;
case 'rpucWidgetCtaResize':
document.querySelector('.rpuc-widget-desktop-dropdown').style.height = _ev.data.params.height + 'px';
break;
case 'itemRpucWidgetCtaClicked':
showDockedWidget();
// showPopupWidget();
break;
case 'rpucWidgetWindowMinimize':
hideWidget();
break;
case 'rpucMaximizeChatClick':
if (document.querySelector('.rpucIframeHolder.docked')) {
hideWidget();
hideProactiveChat();
} else {
showDockedWidget();
}
break;
case 'rpucWidgetWindowClose':
closeWidget();
break;
case 'widgetrightHeight':
case 'widgetleftHeight':
case 'widgetCtaHeight':
var ctaElement = window.rp.widget.ctaElm;
ctaElement.height = "";
ctaElement.height = (_ev.data.params.height) + "px";
ctaElement.style.top = (parseInt(window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight) - _ev.data.params.height )/2 + 'px';
ctaElement.style.visibility = 'visible';
// containerRight.style.height = ctaElement.height;
break;
case 'widgetCtaWidth':
var ctaElement = window.rp.widget.ctaElm;
ctaElement.width = "";
ctaElement.width = _ev.data.params.width + "px";
//document.querySelector('.rpuc-widget-live-comm-container-bottom').style.width = _ev.data.params.width + 'px';
ctaElement.style.visibility = 'visible';
break;
case 'proactiveChat':
window.rp.widget.log('proactive chat action event')
var action = _ev.data.params.start;
document.getElementsByClassName('rpucIframeProactive')[0].classList.remove('rpuc-proactive-modal');
document.getElementById('proactiveIframe').style.display = 'none';
if(typeof communicationIframe != 'undefined') {
communicationIframe.postMessage({event_name: 'proactiveChat', params: { start: action }}, '*');
}
if (action) {
hideProactiveChat();
showDockedWidget();
// logic to show pop up widget when that gets created
// showPopupWidget();
} else {
//clicked cancel
hideProactiveChat();
if (document.querySelector('[class*="rpuc-widget-live-comm-container-"]')) {
document.querySelector('[class*="rpuc-widget-live-comm-container-"]').style.display = "block";
}
}
break;
case 'proactiveChatIframeResize':
var iframe = document.getElementById('proactiveIframe');
iframe.style.setProperty('height', _ev.data.params.height + "px");
break;
case 'showWidget':
if (_ev.data.params.type === 'popup') {
window.rp.widget.log('popup widget not available yet');
// showPopupWidget();
/*** Pop up widget will default to docked widget for now **/
showDockedWidget();
} else if (_ev.data.params.type === 'docked') {
showDockedWidget();
}
break;
case 'ucWidgetUnreadMessages':
window.rp.widget.log('New message received', _ev);
if (!window.rp.widget.supportsLocalStorage()) {
return;
}
var unreadMessages = window.localStorage.getItem('ucWidgetUnreadMessages', true),
ctaElm = window.rp.widget.ctaElm;
if (unreadMessages == null || typeof unreadMessages == "undefined") {
unreadMessages = 0;
}
unreadMessages = parseInt(unreadMessages);
if (isNaN(unreadMessages)) {
unreadMessages = 0;
}
unreadMessages++;
if (typeof _ev.data.count != "undefined") {
if (!isNaN(parseInt(_ev.data.count))) {
unreadMessages = parseInt(_ev.data.count);
} else {
unreadMessages = 0;
}
}
window.localStorage.setItem('ucWidgetUnreadMessages', unreadMessages, true);
// console.log('The type is ' + typeof ctaElm);
if (ctaElm != null){
ctaElm.querySelector('#ucWidgetUnreadMessagesCount').innerText = unreadMessages;
}
break;
case 'RPUCWidgetAgentJoined':
var event, eventName = 'RPUCWidgetAgentJoined';
if (document.createEvent) {
event = document.createEvent("HTMLEvents");
event.initEvent(eventName, true, true);
} else {
event = document.createEventObject();
event.eventType = eventName;
}
event.eventName = eventName;
if (document.createEvent) {
document.dispatchEvent(event);
} else {
document.fireEvent("on" + event.eventType, event);
}
// console.log('trigger ', event);
break;
}
}
window.rpuc = window.rpuc || {};
window.rpuc.showCommunicationWidget = function(type) {
if (type != "docked" && type != "popup") {
type = "docked";
}
window.postMessage({event_name: 'showWidget', params: {type: type}}, '*');
}
window.rpuc.hideCommunicationWidget = function() {
hideWidget();
}
});
}