Add cookie expiration date

This commit is contained in:
Jeremy Thomas 2018-03-28 09:10:39 +01:00
parent af5e17a96d
commit 1a4c242fc6
2 changed files with 8 additions and 8 deletions

View File

@ -2,14 +2,15 @@ document.addEventListener('DOMContentLoaded', () => {
// Cookies // Cookies
const bdCookies = Cookies.getJSON('bulma') || {}; const cookieBookModalName = 'bulma_closed_book_modal';
const cookieBookModal = Cookies.getJSON(cookieBookModalName) || false;
// Book modal // Book modal
const $bookModal = document.getElementById('bookModal'); const $bookModal = document.getElementById('bookModal');
const $bookModalCloseButtons = getAll('.bd-book-modal-close'); const $bookModalCloseButtons = getAll('.bd-book-modal-close');
if (!bdCookies['closed_book_modal']) { if (!cookieBookModal) {
setTimeout(() => { setTimeout(() => {
openModal('bookModal'); openModal('bookModal');
}, 5000); }, 5000);
@ -19,8 +20,7 @@ document.addEventListener('DOMContentLoaded', () => {
$bookModalCloseButtons.forEach($el => { $bookModalCloseButtons.forEach($el => {
$el.addEventListener('click', event => { $el.addEventListener('click', event => {
event.stopPropagation(); event.stopPropagation();
bdCookies['closed_book_modal'] = true; Cookies.set(cookieBookModalName, true, { expires: 30 });
Cookies.set('bulma', bdCookies);
}); });
}); });
} }

View File

@ -4,14 +4,15 @@ document.addEventListener('DOMContentLoaded', function () {
// Cookies // Cookies
var bdCookies = Cookies.getJSON('bulma') || {}; var cookieBookModalName = 'bulma_closed_book_modal';
var cookieBookModal = Cookies.getJSON(cookieBookModalName) || false;
// Book modal // Book modal
var $bookModal = document.getElementById('bookModal'); var $bookModal = document.getElementById('bookModal');
var $bookModalCloseButtons = getAll('.bd-book-modal-close'); var $bookModalCloseButtons = getAll('.bd-book-modal-close');
if (!bdCookies['closed_book_modal']) { if (!cookieBookModal) {
setTimeout(function () { setTimeout(function () {
openModal('bookModal'); openModal('bookModal');
}, 5000); }, 5000);
@ -21,8 +22,7 @@ document.addEventListener('DOMContentLoaded', function () {
$bookModalCloseButtons.forEach(function ($el) { $bookModalCloseButtons.forEach(function ($el) {
$el.addEventListener('click', function (event) { $el.addEventListener('click', function (event) {
event.stopPropagation(); event.stopPropagation();
bdCookies['closed_book_modal'] = true; Cookies.set(cookieBookModalName, true, { expires: 30 });
Cookies.set('bulma', bdCookies);
}); });
}); });
} }