Skip to content

Commit

Permalink
Merge pull request #49472 from shurup/fix-banner-dismiss-js
Browse files Browse the repository at this point in the history
Fix JavaScript null object error in banner-dismiss.js
  • Loading branch information
k8s-ci-robot authored Jan 17, 2025
2 parents de4903d + 2c59879 commit a41eff0
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 a41eff0

Please # to comment.