Merge pull request #49472 from shurup/fix-banner-dismiss-js

Fix JavaScript null object error in banner-dismiss.js
pull/49474/head
Kubernetes Prow Robot 2025-01-17 01:42:06 -08:00 committed by GitHub
commit a41eff0465
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 14 deletions

View File

@ -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();
});
}
});