Prevent displaying popup after dismiss

[MAILPOET-2741]
This commit is contained in:
Pavel Dohnal
2020-03-25 14:27:11 +01:00
committed by Veljko V
parent fd0abffd3a
commit bb5abe8f24

View File

@@ -2,6 +2,26 @@ import MailPoet from 'mailpoet';
import jQuery from 'jquery';
import 'parsleyjs';
function setCookie(name, value, days) {
let expires = '';
if (days) {
const date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = `; expires=${date.toUTCString()}`;
}
document.cookie = `${name}=${value}${expires}; path=/`;
}
function getCookie(name) {
const nameEQ = `${name}=`;
const ca = document.cookie.split(';');
for (let i = 0; i < ca.length; i += 1) {
let c = ca[i];
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
jQuery(($) => {
window.reCaptchaCallback = function reCaptchaCallback() {
$('.mailpoet_recaptcha').each((index, element) => {
@@ -38,9 +58,13 @@ jQuery(($) => {
$('.mailpoet_popup_close_icon').click((event) => {
const closeIcon = $(event.target);
closeIcon.parent().removeClass('active');
setCookie('popup_form_dismissed', '1', 365);
});
$('div.mailpoet_form_popup').each((index, element) => {
const cookieValue = getCookie('popup_form_dismissed');
if (cookieValue === '1') return;
const formDiv = $(element);
const form = formDiv.find('form');
const background = form.data('background-color');