Oops! Something went wrong while submitting the form.
// Remove popup modal element from DOM
function removeWfPopup()
{
var popup_wfs = document.getElementsByClassName('popup__wrapper');
if(popup_wfs != null && popup_wfs.length > 0)
{
var popup_wf = popup_wfs[0];
if(popup_wf != null)
{
popup_wf.parentNode.removeChild(popup_wf);
}
}
}
function closeWfPopup() {
// remove popup element from DOM
removeWfPopup();
// Creates cookie expiring 30 days later
Cookies.set('popup-wf', 'value', { expires: 30 })
}
function showWfPopup()
{
var popup_wfs = document.getElementsByClassName('popup__wrapper');
if(popup_wfs != null && popup_wfs.length > 0)
{
var popup_wf = popup_wfs[0];
if(popup_wf != null)
{
if(popup_wf.style.display != 'flex')
{
popup_wf.style.display = 'flex';
}
}
}
}
function getScrollPercent() {
var h = document.documentElement,
b = document.body,
st = 'scrollTop',
sh = 'scrollHeight';
return (h[st]||b[st]) / ((h[sh]||b[sh]) - h.clientHeight) * 100;
}
document.addEventListener("DOMContentLoaded", function(event) {
// Check if cookie exists
if (Cookies.get('popup-wf')) {
// If cookie is found, removes the popup element from DOM
removeWfPopup();
}
// Cookie doesn't exist yet, so we can show the pop-up
else
{
// Add event on close button to close the popup
var popup_wf_closes = document.getElementsByClassName('popup__close-btn');
if(popup_wf_closes != null && popup_wf_closes.length > 0)
{
var popup_wf_close = popup_wf_closes[0];
if(popup_wf_close != null)
{
popup_wf_close.addEventListener('click', function(e){
closeWfPopup();
});
}
}
// Add event to show the popup when mouse leaves the screen (doesn't work on mobile)
// document.addEventListener("mouseleave") seems to be not fired on new firefox version, mouseleave need to be attached to an element like body, or a child element.
document.body.addEventListener("mouseleave", function(event){
if(event.clientY <= 0 || event.clientX <= 0 || (event.clientX >= window.innerWidth || event.clientY >= window.innerHeight))
{
showWfPopup();
}
});
// Add event to not show the popup again if the form is submitted successfully
// Uncomment if your popup includes a form to be used only once by users, after adding if 'popup_success' to the Webflow Success Message form element
popup_wf_sucess = document.getElementById('popup_success');
if(popup_wf_sucess != null)
{
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutationRecord) {
if (mutationRecord.type === 'attributes')
{
var style_attr = popup_wf_sucess.getAttribute("style");
if(style_attr != null && style_attr.replace(/\s+/g, '').includes('display:block'))
{
// Creates cookie expiring 30 days later
Cookies.set('popup-wf', 'value', { expires: 30 });
}
}
});
});
observer.observe(popup_wf_sucess, { attributes : true, attributeFilter : ['style'] });
}
// Add event to show popup when use has scrolled 50% of the screen (so it can be shown on mobile too)
window.addEventListener('scroll', function() {
if(getScrollPercent()>50)
{
showWfPopup();
}
});
// Showing popup after XX seconds, in case the page cannot be scrolled because its height is smaller than screen height
setTimeout("showWfPopup()", 100);
}
});