Skip to content

Commit

Permalink
Fix banner-dismiss.js null object
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Shurupov <dmitry.shurupov@palark.com>
  • Loading branch information
shurup committed Jan 17, 2025
1 parent de4903d commit 2c59879
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions assets/js/banner-dismiss.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,25 @@ $(document).ready(function() {

/* Check the presence of a cookie */
let announcement = document.querySelector("#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") {
announcement.remove(); // Remove the announcement if the cookie is set
}
else {
announcement.classList.add('display-announcement') // Display the announcement if the cookie is not set
}
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") {
announcement.remove(); // Remove the announcement if the cookie is set
}
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');
button.removeAttribute('style');
button.addEventListener('click', function() {
setCookie(token, "true",
button.getAttribute('data-ttl')); // Set a cookie with time to live parameter
announcement.remove();
});
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();
});
}
});

0 comments on commit 2c59879

Please # to comment.