// ---- RULES ---- // DESKTOP - conditions // - A popup is set for the current page // - Popup never shown to the user on any page // - The user scroll 25% of the page or more // - The page is loaded since 5 seconds or more // - The GET STARTED popup is not visible // - The user did not interacted with the page // MOBILE - conditions // - A popup is set for the current page // - Popup never shown to the user on any page // - The user scroll 75% of the page or more // - The page is loaded since 12 seconds or more // - The GET STARTED popup is not visible // - The user did not interacted with the page (limited to CTA) var QUERY_URL = 'https://www.nextiva.com/jbx/engine/q.php'; var popupHistory = []; var popupurl = null; var popupid = null; var isTouchDevice = false; var startTime = 0; var linkedPopup = false; var isBlog = document.location.pathname.indexOf('/blog') === 0; var disablePopup = false; var innerCategory = ''; var XmaxScrolled = 0; var Xdelay = 0; var Xmousey = 0; var XmouseLock = true; var XdisplayedOnce = false; var XfirstUse = true; var jbx_delay_mobile = 12; var jbx_scroll_mobile = 75; var jbx_delay_desktop = 5; var jbx_scroll_desktop = 25; console.log('JBX jbx.js loaded') window.addEventListener('touchstart', function() { isTouchDevice = true; }); window.onload = function() { setTimeout(function() { jbx_init(); }, 250); // Get started - Set local storage on submit if(document.getElementsByName('submitBttn')[0] !== null) { document.getElementsByName('submitBttn')[0].onclick = function() { localStorage.setItem('jbx_form_submit', 'AAAA00'); }; } // nextiva-pricing - Set local storage on submit if(document.querySelector('#trial-communication') !== null) { if(document.querySelector('#trial-communication').querySelector('.submitBttn') !== null) { if(document.querySelector('#trial-communication').querySelector('.submitBttn').querySelector('.validation-bttn.nextiva-blue-bttn') !== null) { document.querySelector('#trial-communication').querySelector('.submitBttn').querySelector('.validation-bttn.nextiva-blue-bttn').onclick=function() {localStorage.setItem('jbx_form_submit', 'AAAA00');} } } } }; function extractCategory() { var bodytext = document.querySelectorAll('body')[0].innerHTML; if(bodytext.indexOf('
0) { bodytext = bodytext.split('
0) { innerCategory = bodytext.split('category-')[1]; if(innerCategory.indexOf('"') > -1) innerCategory = innerCategory.split('"')[0]; if(innerCategory.indexOf(' ') > -1) innerCategory = innerCategory.split(' ')[0]; } } } var intervalStarted = false; function jbx_init() { QUERY_URL = 'https://www.nextiva.com/jbx/engine/q.php'; extractCategory(); popupHistory = JSON.parse(memget('jbx_popupHistory', '[]')); var thisurl = String(document.location.href).split('?')[0].split('#')[0]; var payload = { query:'url_to_popup', url:thisurl, category:(isBlog ? innerCategory : '') }; x_query(true, payload, function(status, json) { console.log(json) json = typeof json === 'string' ? JSON.parse(json) : json; if(typeof json.popupid !== 'undefined') { if(!isInPopupHistory(json.popupid)) { popupurl = json.popupurl; FILTER_KEY = localStorage.getItem('jbx_form_submit') === null ? 'NO_FILTER' : localStorage.getItem('jbx_form_submit'); popupid = json.popupid if(popupurl !== null) { if(popupurl.indexOf('filter=' + FILTER_KEY) === -1) { insertPopFrame(); var date = new Date(); startTime = date.getTime(); if(!intervalStarted) { setInterval('jbx_timer()', 100); intervalStarted = true; } } } } else { jbx = null; } } }); } function insertPopFrame() { var rt = popupurl === null ? 'about:blank' : popupurl; if(QS('.popup_iframe') === null) { var H = ""; document.body.insertAdjacentHTML('beforeEnd', H); } else { QS('.popup_iframe').style.display = 'none'; QS('.popup_iframe').src = rt; } } function popup_iframe_onload() { if(linkedPopup) showJBXpopup(); } function jbx_timer() { var date = new Date(); Xdelay = ~~((date. getTime() - startTime) / 1000); var scrollPos = document.documentElement.scrollTop; var scrollMax = document.documentElement.scrollHeight - document.documentElement.clientHeight; var scroll = Math.ceil(scrollPos / scrollMax * 100); if(XmaxScrolled < scroll) XmaxScrolled = scroll; var colorMouse = !XmouseLock ? 'rgb(34,181,115)' : 'rgb(211,42,79)'; if(isTouchDevice) { var colorTime = Xdelay >= jbx_delay_mobile ? 'rgb(34,181,115)' : 'rgb(211,42,79)'; var colorScroll = XmaxScrolled >= jbx_scroll_mobile ? 'rgb(34,181,115)' : 'rgb(211,42,79)'; } else { var colorTime = Xdelay >= jbx_delay_desktop ? 'rgb(34,181,115)' : 'rgb(211,42,79)'; var colorScroll = XmaxScrolled >= jbx_scroll_desktop ? 'rgb(34,181,115)' : 'rgb(211,42,79)'; } } document.ontouchmove = function(event) { if(isBlog) disablePopup = true; if(popupurl !== null && document.querySelector('.slideinQuote') === null && jbx_disabled_after_interaction === false) { jbx_timer(); var scrollRef = jbx_scroll_mobile; var XdelayRef = jbx_delay_mobile; if(XmaxScrolled >= scrollRef && Xdelay >= XdelayRef) { if(!XdisplayedOnce) { XdisplayedOnce = true; showJBXpopup(); report_hit(); } } } } document.onmousemove = function(event) { if(popupurl !== null && document.querySelector('.slideinQuote') === null && jbx_disabled_after_interaction === false) { Xmousey = ~~(event.pageY - document.documentElement.scrollTop); if(Xmousey > 100) XmouseLock = false; var scrollRef = isTouchDevice ? jbx_scroll_mobile : jbx_scroll_desktop; var XdelayRef = isTouchDevice ? jbx_delay_mobile : jbx_delay_desktop; if(QS('#quote-slidein') === null || QS('#quote-slidein').style !== 'container-fluid h-100 active') { if(XmaxScrolled >= scrollRef && Xdelay >= XdelayRef && !XmouseLock && (Xmousey < 40 || isTouchDevice)) { if(!XdisplayedOnce) { XdisplayedOnce = true; showJBXpopup(); report_hit(); } } } } } var jbx_disabled_after_interaction = false; document.onclick = function(event) { if(!jbx_disabled_after_interaction) { jbx_disabled_after_interaction = true; console.log('JBX disabled after user interaction') } } function showJBXpopup() { if(!disablePopup) { QS('.popup_iframe').style.opacity = 0; addToPopupHistory(); apply_popup_data(); setTimeout(function() { QS('.popup_iframe').style.display = 'block'; setTimeout(function() { document.body.style.overflow = 'hidden'; QS('.popup_iframe').style.opacity = 1; }, 25); }, 25); } } function jbx_popup_close() { // Called from popup hide_jbxPopup(); } function isInPopupHistory(pid) { if(QS('#JBXTRACE') !== null) return false; for(var i in popupHistory) { var daysBefore = new Date().getTime() - 1000 * 60 * 60 * 24 * 15; if(pid === popupHistory[i].id && popupHistory[i].date > daysBefore) return true; } return false; } function addToPopupHistory() { var updated = false; var stamp = new Date().getTime(); for(var i in popupHistory) { if(popupid === popupHistory[i].id) { popupHistory[i].date = stamp; updated = true; } } if(!updated) { popupHistory.push({id:popupid, date:stamp}); } memset('jbx_popupHistory', JSON.stringify(popupHistory)); } function hide_jbxPopup() { var elem = document.querySelector('.popup_iframe'); elem.parentNode.removeChild(elem); //QS('.popup_iframe').style.display = 'none'; //QS('.popup_iframe_layer').style.opacity = 0; document.body.style.overflow = 'auto'; //setTimeout(function() { // QS('.popup_iframe_layer').style.display = 'none'; //}, 500); } function report_hit() { //QUERY_URL = "m/engine/q.php"; //x_query(true, { lib: 'jbx', query: 'hit', popupid: popupid, touchDevice: isTouchDevice }, function(status, json) { console.log(json.args) }); } function QS(element) { return document.querySelector(element); } function x_post(sObject, sQueryCallback, forceTextResponse, bypassQueue) { x_query(true, sObject, sQueryCallback, forceTextResponse === void 0 ? false : forceTextResponse, bypassQueue === void 0 ? false : bypassQueue); } function x_get(sObject, sQueryCallback, forceTextResponse, bypassQueue) { x_query(false, sObject, sQueryCallback, forceTextResponse === void 0 ? false : forceTextResponse, bypassQueue === void 0 ? false : bypassQueue); } function x_query(isPost, get_object, get_callback, forceTextResponse, bypassQueue) { get_callback = get_callback = void 0 ? null : get_callback; forceTextResponse = forceTextResponse === void 0 ? false : forceTextResponse; bypassQueue = bypassQueue === void 0 ? false : bypassQueue; if(userid === void 0) var userid = top.userid; if(userid !== '') { if(top.currentToken === null) { return true; } else { var http = new XMLHttpRequest(); http.onreadystatechange = function() { if(http.readyState == XMLHttpRequest.DONE) { if(http.status == 500) { console.error('Error 500 on _query', http.statusText, get_object); x_query(isPost, get_object, function(status, text) { console.log(text) }, true, true); } else { if(http.status === 401) { top.token_needed(); } else { if(typeof get_callback === 'function') { if(forceTextResponse) { get_callback(http.status == 200, http.responseText); } else { if(http.response === null) { console.error('Query returned NULL:', get_object, http.statusText); x_query(isPost, get_object, function(status, text) { console.log(text) }, true, true); } else { if(http.response.lastError !== void 0 && http.response.lastError !== null) { console.error(http.response.lastError); } var json = typeof http.response === 'string' ? JSON.parse(http.response) : http.response; get_callback(http.status == 200, http.response); } } } } } } } http.open(isPost ? 'POST' : 'GET', QUERY_URL); http.timeout = isPost? 10000 : 2000; http.responseType = forceTextResponse ? 'text' : 'json'; http.setRequestHeader("responseType", forceTextResponse ? 'text' : 'json'); http.setRequestHeader("Cache-Control", "no-cache"); http.setRequestHeader("Content-Type", isPost ? "application/x-www-form-urlencoded" : "Content-Type: application/json"); if(!isPost) http.setRequestHeader("args", window.btoa(JSON.stringify(get_object))); http.setRequestHeader("token", top.activeToken); http.setRequestHeader("companyid", window.btoa(top.companyid)); http.setRequestHeader("userid", window.btoa(top.userid)); http.setRequestHeader("email", window.btoa(top.email)); http.setRequestHeader("deviceid", top.deviceid); http.send(isPost ? 'args=' + JSON.stringify(get_object) : ''); return true; } } else { if(typeof get_callback === 'function') { get_callback(0, forceTextResponse ? '' : {}); } } } function getArgs() { var vars = {}; var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { vars[key] = value; }); return vars; } function apply_popup_data() { QS('.popup_iframe').src = popupurl; QS('.popup_iframe').style.width = '100%'; QS('.popup_iframe').style.height = '100%'; }