@@ -21,21 +21,25 @@ $(document).ready(function() {
21
21
22
22
/* Check the presence of a cookie */
23
23
let announcement = document . querySelector ( "#announcement" ) ;
24
- let token = `announcement_ack_${ announcement . getAttribute ( 'data-announcement-name' ) . replace ( / \s / g, '_' ) } ` ; // Generate the unique token for announcement
25
- let acknowledged = getCookie ( token ) ;
26
- if ( acknowledged === "true" ) {
27
- announcement . remove ( ) ; // Remove the announcement if the cookie is set
28
- }
29
- else {
30
- announcement . classList . add ( 'display-announcement' ) // Display the announcement if the cookie is not set
31
- }
24
+ if ( announcement ) {
25
+ let token = `announcement_ack_${ announcement . getAttribute ( 'data-announcement-name' ) . replace ( / \s / g, '_' ) } ` ; // Generate the unique token for announcement
26
+ let acknowledged = getCookie ( token ) ;
27
+ if ( acknowledged === "true" ) {
28
+ announcement . remove ( ) ; // Remove the announcement if the cookie is set
29
+ }
30
+ else {
31
+ announcement . classList . add ( 'display-announcement' ) // Display the announcement if the cookie is not set
32
+ }
33
+ }
32
34
33
35
/* Driver code to set the cookie */
34
36
let button = document . querySelector ( '#banner-dismiss' ) ;
35
- button . removeAttribute ( 'style' ) ;
36
- button . addEventListener ( 'click' , function ( ) {
37
- setCookie ( token , "true" ,
38
- button . getAttribute ( 'data-ttl' ) ) ; // Set a cookie with time to live parameter
39
- announcement . remove ( ) ;
40
- } ) ;
37
+ if ( button ) {
38
+ button . removeAttribute ( 'style' ) ;
39
+ button . addEventListener ( 'click' , function ( ) {
40
+ setCookie ( token , "true" ,
41
+ button . getAttribute ( 'data-ttl' ) ) ; // Set a cookie with time to live parameter
42
+ announcement . remove ( ) ;
43
+ } ) ;
44
+ }
41
45
} ) ;
0 commit comments