(function (){ // ---------------------------- // SB CONSTANTS // ---------------------------- const intends = { immediately: 1, to_title: 90, // this property is not in use as per previous logic befoer adding 3 seconds delay intends to_middle: 100, // this property is not in use as per previous logic befoer adding 3 seconds delay intends to_leave: 0 }; const SBTypes = { OMNIBAR: 'omni_bar', FULLPAGE: 'full_page', LEADPAX: 'leadpax' }; // ---------------------------- // SB Global Variables // ---------------------------- var windowWidth = screen.width, iframe = document.getElementById("stickyIframe"), body = document.body, html = document.documentElement, loadFirstTime = false, iframeScriptsFunction = document.getElementById("stickyIframe").contentWindow; // ---------------------------- // SB EVENTS // ---------------------------- //Exit Intend addEvent(document.body, "mouseleave", function (e) { e = e ? e : window.event; var from = e.relatedTarget || e.toElement; if (!from) { onExitIntent(e) } }); document.addEventListener("scroll", onScroll); window.addEventListener('message', function (e) { var msg = e.data if(msg == 'lpStickyClosed'){ hideSticky(); } }); if(window.StickyData && StickyData.stickybar_style == SBTypes.LEADPAX) { window.onresize = leadPaxResponsive; }else{ // Omni bar Resizing Function window.onresize = omniBarResponsive; } // This function is using to checking Fonts are loaded then AdjustIframeSize function will be called. // This function is conflicting with binding on document that's why I added here... var iframeDoc = iframe.contentDocument || iframe.contentWindow; iframeDoc.fonts.onloadingdone = function (fontFaceSetEvent) { if(document.getElementById("placeholderId").style.visibility == "visible"){ adjustIframeSize(false); } }; document.getElementById('show-st').addEventListener('click', function() { loadFirstTime = true; hideToggleBtn(); // Hide Show-St Icon before Show CP. showSticky(); }) window.onbeforeunload = function(e) { onExitIntent(e); } window.addEventListener("blur", function(evt){ onExitIntent(evt); }, false); // This content will be triggered after loading the iframe. if (window.StickyData && parseInt(window.StickyData.intend) != intends.immediately) { hideSticky() onScroll() if(parseInt(window.StickyData.intend) === 0) { return; } /* add the sticky data intend === 0 to hide the stickybar by default and show when user intend to leave */ if(parseInt(window.StickyData.intend)!==intends.to_leave || parseInt(window.StickyData.intend)!==intends.to_title || parseInt(window.StickyData.intend)!==intends.to_middle){ let timeDelay = getTimeInterval(window.StickyData.intend); if(timeDelay > 0){ timeDelay = timeDelay - 750; //reducing 750 because it was added on scripts.js on initIframe(); } showStickyAfterInterval(timeDelay); } } else { loadFirstTime = true; showSticky() } leadPaxResponsive(); function leadPaxResponsive(){ if(window.StickyData && StickyData.stickybar_style == SBTypes.LEADPAX) { if(screen.width < 992){ document.getElementById("placeholderId").classList.add(StickyData.leadpax.stickybar_placed, 'leadpax-scale'); document.getElementById("placeholderId").classList.remove('shake'); document.getElementById("placeholderId").classList.add('mobileshake'); }else{ document.getElementById("placeholderId").classList.remove('mobileshake', 'top_left', 'top_right', 'bottom_left', 'bottom_right','leadpax-scale'); document.getElementById("placeholderId").classList.add('shake'); } } } // ---------------------------- // Helper Function // ---------------------------- function addEvent(obj, evt, fn) { if (obj.addEventListener) { obj.addEventListener(evt, fn, false); } else if (obj.attachEvent) { obj.attachEvent("on" + evt, fn); } } function showStickyAfterInterval(stickyInterval) { let interval = 1000; // 1 second let elapsedTime = 0; // interval that logs each second let intervalId = setInterval(() => { elapsedTime += interval; console.log(new Date().toLocaleTimeString('en-GB', { hour12: false }),`rbp.counter: ${elapsedTime / 1000}s`); }, interval); setTimeout(() => { clearInterval(intervalId); // Clear the interval loadFirstTime = true; showSticky() console.log(new Date().toLocaleTimeString('en-GB', { hour12: false }),"rbp.ready") }, stickyInterval); } /* intend = Delay value in seconds */ function getTimeInterval(intend) { var $interval = 0; switch (+intend) { case 8: $interval = 3; break; case 2: $interval = 5; break; case 3: $interval = 10; break; case 4: $interval = 20; break; case 5: $interval = 30; break; case 6: $interval = 45; break; case 7: $interval = 60; break; default: $interval = 0; break; } console.log(new Date().toLocaleTimeString('en-GB', { hour12: false }),"rbp.rendering.init",intend,$interval) var $after_margin = 1.5; return ($interval + $after_margin) * 1000; } function getFirstTitleTag() { var titleTag = document.getElementsByTagName('h1')[0]; if (!titleTag) titleTag = document.getElementsByTagName('h2')[0]; if (!titleTag) titleTag = document.getElementsByTagName('h3')[0]; if (!titleTag) titleTag = document.getElementsByTagName('h4')[0]; if (!titleTag) titleTag = document.getElementsByTagName('h5')[0]; if (!titleTag) titleTag = document.getElementsByTagName('h6')[0]; return titleTag; } function onScroll(e){ if(onScroll.isShown || !StickyData || !StickyData.hasOwnProperty('intend')){ return } var intendType = StickyData.intend; if([intends.to_title, intends.to_middle].indexOf(+intendType) < 0){ return } var scroll = window.pageYOffset || document.documentElement.scrollTop var height = Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight ); switch(+intendType){ case intends.to_title: var titleTag = getFirstTitleTag() if(!titleTag){ return } // Bounding client rect top can be negative var titleOffsetY = titleTag.getBoundingClientRect().top + scroll if(scroll >= titleOffsetY){ showSticky() onScroll.isShown = true } break; case intends.to_middle: if(scroll >= height / 2){ showSticky() onScroll.isShown = true } break; } } function hideSticky() { document.getElementById('placeholderId').style.display = 'none'; if(onExitIntent.isShown){ document.getElementById('show-st').style.visibility = 'visible'; } // Remove top & bottom padding. if(StickyData.stickybar_style == SBTypes.OMNIBAR){ window.document.body.style.paddingTop = '' window.document.body.style.paddingBottom = '' } } // Adjust Iframe Size on load according to CP style. function adjustIframeSize(hideStickyBar) { let stickyData = window.StickyData; let _mainDiv = document.getElementById('placeholderId'); let height = getIframeContentHeight(_mainDiv, hideStickyBar); if (stickyData) { if(!height) return; // leadPaxContentHeight is Current Content of LeadPax Height let leadPaxContentHeight = height; if(StickyData.stickybar_style === SBTypes.LEADPAX){ /* We were getting the height as per the content earlier and were checking if the height is more than slider and were assigning as per that but now we are having scroll and passing the height of content to the iframe and parent div and assigning the max height as vh so the scroll will be shown if content is more than the viewport height that's why we don't need to perform any check regarding the height either it is more than 600 or less*/ // leadPaxHeight is slider height of leadPax from Backend // let leadPaxHeight = parseInt(StickyData.leadpax.stickybar_start_size); // // if(leadPaxContentHeight > leadPaxHeight){ // leadPaxHeight += leadPaxContentHeight - leadPaxHeight; // leadPaxHeight += parseInt(StickyData.border_size) * 2; // } // // let calculatedHeight = leadPaxHeight; // Add Image Space if we have image on the LeadPax Height. // if(stringToBooleanToggleValue(StickyData.leadpax.content.profile_image.show_image)){ // leadPaxHeight = leadPaxHeight + 60; // } // Remove Border from the Inner Content Height // calculatedHeight = calculatedHeight - parseInt(StickyData.border_size) * 2; // If we set the slider height on the leadpax we also need to update height of DIV in the Iframe let leadPaxWrapper = iframe.contentWindow.document.getElementById('sb-leadpax-box-wrap'); let leadPaxBG = iframe.contentWindow.document.getElementById('data-sb-backgound'); let borderSize = ((parseInt(StickyData.border_size) * 2) - 40) + 'px'; if(stringToBooleanToggleValue(StickyData.leadpax.content.profile_image.show_image)) { iframe.style.height = (parseInt(leadPaxContentHeight + 2) + (parseInt(StickyData.border_size) * 2) + 60) + 'px'; iframe.style.maxHeight = `calc(${borderSize} + 100vh)`; _mainDiv.style.maxHeight = `calc(${borderSize} + 100vh)`; _mainDiv.style.height = (parseInt(leadPaxContentHeight + 2) + (parseInt(StickyData.border_size) * 2) + 60) + 'px'; leadPaxBG.style.height =(parseInt(leadPaxContentHeight + 2) + (parseInt(StickyData.border_size) * 2)) + 'px'; } else { iframe.style.height = (parseInt(leadPaxContentHeight + 2) + (parseInt(StickyData.border_size) * 2)) + 'px'; iframe.style.maxHeight = `calc(${borderSize} + 100vh)`; _mainDiv.style.maxHeight = `calc(${borderSize} + 100vh)`; _mainDiv.style.height = (parseInt(leadPaxContentHeight + 2) + (parseInt(StickyData.border_size) * 2)) + 'px'; leadPaxBG.style.height =(parseInt(leadPaxContentHeight + 2) + (parseInt(StickyData.border_size) * 2)) + 'px'; } // Set Scroll visibility hidden because scrollbar appears for few milliseconds due to fonts loading delay let scrollBarVeritical = iframe.contentWindow.document.getElementById('mCSB_1_scrollbar_vertical'); scrollBarVeritical.style.visibility = "hidden"; // We have the leadpax Height slider maximum value is 600 // So if the content height is greater then 600 then we set the Slider Height not Content Height // if(leadPaxContentHeight <= 600){ // // // If the content height is greater then Slider Height then we add the difference in the height. // if(leadPaxContentHeight > leadPaxHeight){ // leadPaxHeight += leadPaxContentHeight - leadPaxHeight; // leadPaxHeight += parseInt(StickyData.border_size) * 2; // } // // let calculatedHeight = leadPaxHeight; // // // Add Image Space if we have image on the LeadPax Height. // if(stringToBooleanToggleValue(StickyData.leadpax.content.profile_image.show_image)){ // leadPaxHeight = leadPaxHeight + 60; // } // // // Remove Border from the Inner Content Height // calculatedHeight = calculatedHeight - parseInt(StickyData.border_size) * 2 // // iframe.style.minHeight = leadPaxHeight + 'px'; // _mainDiv.style.minHeight = leadPaxHeight + 'px'; // _mainDiv.style.height = leadPaxHeight + 'px'; // // // If we set the slider height on the leadpax we also need to update height of DIV in the Iframe // let leadPaxWrapper = iframe.contentWindow.document.getElementById('sb-leadpax-box-wrap'); // if(leadPaxWrapper){ // leadPaxWrapper.style.height = calculatedHeight + 'px'; // } // // }else{ // if leadPax have more then 600 then get current content height // // // Add Image Space if we have image on the LeadPax Height. // if(stringToBooleanToggleValue(StickyData.leadpax.content.profile_image.show_image)){ // leadPaxContentHeight = leadPaxContentHeight + 60; // } // // // Add Border from the Inner Content Height // leadPaxContentHeight = leadPaxContentHeight + parseInt(StickyData.border_size) * 2 // // iframe.style.minHeight = leadPaxContentHeight + 'px'; // _mainDiv.style.minHeight = leadPaxContentHeight + 'px'; // _mainDiv.style.height = height+'px'; // // let leadPaxWrapper = iframe.contentWindow.document.getElementById('sb-leadpax-box-wrap'); // if(leadPaxWrapper){ // leadPaxWrapper.style.height = height + 'px'; // } // } }else{ if(StickyData.stickybar_style === SBTypes.OMNIBAR && height){ ombiBarContentHeight = (StickyBarData.sticky_button_preview_styles)?JSON.parse(StickyBarData.sticky_button_preview_styles).omniBarSize: leadPaxContentHeight+'px'; if(height < parseInt(ombiBarContentHeight)){ height = parseInt(ombiBarContentHeight); } // If we set the slider height on the leadpax we also need to update height of DIV in the Iframe let leadPaxWrapper = iframe.contentWindow.document.getElementById('sticky-bar'); if(leadPaxWrapper){ leadPaxWrapper.style.minHeight = ombiBarContentHeight; } //if stickybar style is omni bar then min height and height will be set on iframe and main div (placeholderId) iframe.style.minHeight = ombiBarContentHeight; _mainDiv.style.minHeight = ombiBarContentHeight; _mainDiv.style.height = height+'px'; if(!hideStickyBar){ if(StickyData.omni_bar.stickybar_placed === "top") { window.document.body.style.setProperty('padding-top', height+'px', 'important') } else { window.document.body.style.setProperty('padding-bottom', height+'px', 'important') } } } } } else { _mainDiv.style.height = '110px'; } return height; } function showSticky() { window.document.getElementById('placeholderId').style.visibility = 'hidden'; var _mainDiv = window.document.getElementById('placeholderId'); if(loadFirstTime){ _mainDiv.style.display = 'block'; adjustIframeSize(true); } hideToggleBtn(); // Hide Show-St Icon before Show CP. if(StickyData.stickybar_style === SBTypes.LEADPAX){ _mainDiv.style.display = 'block'; }else{ // Make visible for both Omnibar & FullPage _mainDiv.style.display = 'flex'; _mainDiv.style.visibility = 'visible'; adjustIframeSize(false); } onExitIntent.isShown = true; } function getIframeContentHeight(_mainDiv, hideCP=false){ let _div = null, _height = 0; _mainDiv.style.visibility = 'hidden'; if(StickyData.stickybar_style == SBTypes.LEADPAX){ _div = iframe.contentWindow.document.getElementById('sb-leadpax-box-wrap'); }else{ _div = iframe.contentWindow.document.getElementById('sticky-bar'); } if (!_div) return // _height = parseInt(_div.getBoundingClientRect().height); _height = parseInt(_div.offsetHeight); _mainDiv.style.visibility = 'visible'; if(hideCP){ _mainDiv.style.display = 'none'; }else{ _mainDiv.style.display = 'flex'; } return _height; } function hideToggleBtn() { document.getElementById('show-st').style.visibility = 'hidden'; if(window.StickyData.stickybar_style == "full_page" && window.parent) { window.parent.document.body.style.overflow = 'hidden'; } } function isTouchScreendevice() { return 'ontouchstart' in window || navigator.maxTouchPoints; }; function onExitIntent(e) { if (!onExitIntent.isShown && window.StickyData && parseInt(window.StickyData.intend) == intends.to_leave){ loadFirstTime = true; showSticky(); iframeScriptsFunction.setCloseIconSetTimeOut(); } } if(StickyData.stickybar_style != "leadpax"){ iframeScriptsFunction.loadFontSize(); iframeScriptsFunction.fontChanges(); if(onExitIntent.isShown && parseInt(window.StickyData.intend) == intends.immediately){ adjustIframeSize(false); } } function omniBarResponsive(){ iframeScriptsFunction.fontChanges(); let hide_stickybar = false; var pl = document.getElementById("placeholderId"); if (window.getComputedStyle(pl).display === "none") { hide_stickybar = true; } adjustIframeSize(hide_stickybar); } })()