-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
41 lines (29 loc) · 1.21 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';
const ddyPopup = document.querySelector('#ddy-newsletter-popup');
if (ddyPopup) {
const openBtn = document.getElementById('open');
const closeBtn = document.getElementById('close');
const newsContainer = document.getElementById('news');
const disablePopupCheckbox = document.querySelector('#disablePopup')
const isPopupEnabledLSKey = 'isPopupEnabled';
const isFirstVisit = !localStorage[isPopupEnabledLSKey]
const isPopupEnabled = isFirstVisit || JSON.parse(localStorage[isPopupEnabledLSKey])
disablePopupCheckbox.checked = !isPopupEnabled;
if (isPopupEnabled) {
setTimeout(showPopup, 5000);
}
openBtn.addEventListener('click', showPopup);
closeBtn.addEventListener('click', hidePopup);
disablePopupCheckbox.addEventListener('click', toggleAutoPopup);
function showPopup() {
newsContainer.classList.add('show');
openBtn.classList.add('hidden');
}
function hidePopup() {
newsContainer.classList.remove('show');
openBtn.classList.remove('hidden');
}
function toggleAutoPopup() {
localStorage.setItem(isPopupEnabledLSKey, !disablePopupCheckbox.checked)
}
}