Created
April 2, 2019 17:27
-
-
Save crates/4a18b54643bab5fd0d947b9d13a68c74 to your computer and use it in GitHub Desktop.
Drupal / jQuery Exit Modal: Show the user a modal when they are attempting to leave your website
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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