Created
June 28, 2018 19:49
-
-
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
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