Skip to content

Instantly share code, notes, and snippets.

@crates
Created June 28, 2018 19:49
Show Gist options
  • Save crates/a31f5ded1eb7f5cdb1fe6d84c1066cd8 to your computer and use it in GitHub Desktop.
Save crates/a31f5ded1eb7f5cdb1fe6d84c1066cd8 to your computer and use it in GitHub Desktop.
Exit Modal: fires an exit modal when the user seeks to leave the page
(function($, Drupal) {
"use strict";
var exitModalCookie = $.cookie("__exitModal");
// set up exit intent listener to fire modal
var exitIntent = function(e) {
if (e.clientY < 0 ) {
// init remodal
var exitModal = $('[data-remodal-id=exit-modal]').remodal();
exitModal.open();
// prevent sowing this more than once per page
document.removeEventListener('mouseleave', exitIntent, false);
}
}
// if user is logged out. Fire that exit modal.
if (!exitModalCookie) {
document.addEventListener('mouseleave', exitIntent, false);
$.cookie('__exitModal', 1, {path: '/', expires: 1});
}
})(jQuery, Drupal);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment