Fix banner-dismiss.js null object

Signed-off-by: Dmitry Shurupov <dmitry.shurupov@palark.com>
pull/49472/head
Dmitry Shurupov 2025-01-17 15:35:56 +07:00
parent de4903de04
commit 2c598792c4
No known key found for this signature in database
1 changed files with 18 additions and 14 deletions

View File

@ -21,6 +21,7 @@ $(document).ready(function() {
/* Check the presence of a cookie */
let announcement = document.querySelector("#announcement");
if (announcement) {
let token = `announcement_ack_${announcement.getAttribute('data-announcement-name').replace(/\s/g, '_')}`; // Generate the unique token for announcement
let acknowledged = getCookie(token);
if (acknowledged === "true") {
@ -29,13 +30,16 @@ $(document).ready(function() {
else {
announcement.classList.add('display-announcement') // Display the announcement if the cookie is not set
}
}
/* Driver code to set the cookie */
let button = document.querySelector('#banner-dismiss');
if (button) {
button.removeAttribute('style');
button.addEventListener('click', function() {
setCookie(token, "true",
button.getAttribute('data-ttl')); // Set a cookie with time to live parameter
announcement.remove();
});
}
});