-
We use cookies to enhance your experience. Choose the cookies you allow:
-
- Analytics
-
-
-
- Personalization
-
-
-
- Advertisement
-
-
-
+
+
+
We use cookies to enhance your experience. Choose the cookies you allow:
+
+ Analytics
+
+
+ Personalization
+
+
+
+ Advertisement
+
+
+
- `;
+
+`;
- hostComponent.innerHTML += cookieModalStyles + cookieModalHTML;
- handleCookieChoice(hostComponent);
+ // Append styles and HTML to the host component
+ hostComponent.innerHTML = cookieModalStyles + cookieModalHTML;
+
+ // Reference to the modal background for event listeners
+ const modalBackground = hostComponent.querySelector('#cookie-modal-background');
+
+ // Fade in animation
+ setTimeout(() => {
+ modalBackground.classList.add('show');
+ }, 50);
+
+ // Close modal when clicking outside of it
+ modalBackground.addEventListener('click', (event) => {
+ if (event.target === modalBackground) {
+ fadeOutAndRemove();
+ }
+ });
+
+ // Close modal when pressing 'Escape'
+ document.addEventListener('keydown', (event) => {
+ if (event.key === 'Escape') {
+ fadeOutAndRemove();
+ }
+ });
- function handleCookieChoice(hostComponent) {
- const modalBackground = hostComponent.querySelector('#cookie-modal-background');
+ // Handle saving preferences
+ hostComponent.querySelector('#save-preferences').addEventListener('click', () => {
+ localStorage.setItem('analytics-cookies', hostComponent.querySelector('#analytics-cookies').checked);
+ localStorage.setItem(
+ 'personalization-cookies',
+ hostComponent.querySelector('#personalization-cookies').checked
+ );
+ localStorage.setItem(
+ 'advertisement-cookies',
+ hostComponent.querySelector('#advertisement-cookies').checked
+ );
- hostComponent.querySelector('#save-preferences').addEventListener('click', () => {
- localStorage.setItem('analytics-cookies', hostComponent.querySelector('#analytics-cookies').checked);
- localStorage.setItem(
- 'personalization-cookies',
- hostComponent.querySelector('#personalization-cookies').checked
- );
- localStorage.setItem(
- 'advertisement-cookies',
- hostComponent.querySelector('#advertisement-cookies').checked
- );
+ fadeOutAndRemove();
+ });
+ // Fade out and remove the modal
+ function fadeOutAndRemove() {
+ modalBackground.classList.remove('show');
+ setTimeout(() => {
modalBackground.remove();
- });
+ }, 300);
}
};