Display form on mouse exit

[MAILPOET-3057]
This commit is contained in:
Pavel Dohnal
2020-09-03 09:31:00 +02:00
committed by Veljko V
parent ca2d3b75dd
commit 81a37be18f
3 changed files with 26 additions and 6 deletions

View File

@ -70,6 +70,15 @@ jQuery(($) => {
}); });
} }
function doDisplayForm(formDiv, showOverlay) {
formDiv.addClass('active');
checkFormContainer(formDiv);
if (showOverlay) {
formDiv.prev('.mailpoet_form_popup_overlay').addClass('active');
}
}
function showForm(formDiv, showOverlay = false) { function showForm(formDiv, showOverlay = false) {
const form = formDiv.find('form'); const form = formDiv.find('form');
const position = form.data('position'); const position = form.data('position');
@ -82,13 +91,16 @@ jQuery(($) => {
delay = 0; delay = 0;
} }
setTimeout(() => { setTimeout(() => {
formDiv.addClass('active'); doDisplayForm(formDiv, showOverlay);
checkFormContainer(formDiv);
if (showOverlay) {
formDiv.prev('.mailpoet_form_popup_overlay').addClass('active');
}
}, delay * 1000); }, delay * 1000);
const exitIntentEnabled = form.data('exit-intent-enabled');
if (exitIntentEnabled) {
$(document).on('mouseleave', () => {
doDisplayForm(formDiv, showOverlay);
$(document).off('mouseleave');
});
}
} }
const closeForm = (formDiv) => { const closeForm = (formDiv) => {

View File

@ -157,6 +157,13 @@ class DisplayFormInWPContent {
$templateData['position'] = $formSettings['form_placement'][$displayType]['position'] ?? ''; $templateData['position'] = $formSettings['form_placement'][$displayType]['position'] ?? '';
$templateData['backgroundColor'] = $formSettings['backgroundColor'] ?? ''; $templateData['backgroundColor'] = $formSettings['backgroundColor'] ?? '';
$templateData['fontFamily'] = $formSettings['font_family'] ?? ''; $templateData['fontFamily'] = $formSettings['font_family'] ?? '';
$templateData['enableExitIntent'] = false;
if (
isset($formSettings['form_placement'][$displayType]['exit_intent_enabled'])
&& ($formSettings['form_placement'][$displayType]['exit_intent_enabled'] === '1')
) {
$templateData['enableExitIntent'] = true;
}
// generate security token // generate security token
$templateData['token'] = Security::generateToken(); $templateData['token'] = Security::generateToken();

View File

@ -34,6 +34,7 @@
novalidate novalidate
data-delay="<%= delay %>" data-delay="<%= delay %>"
data-position="<%= position %>" data-position="<%= position %>"
data-exit-intent-enabled="<%= enableExitIntent %>"
data-background-color="<%= backgroundColor %>" data-background-color="<%= backgroundColor %>"
data-font-family="<%= fontFamily %>" data-font-family="<%= fontFamily %>"
> >