|
7 | 7 | * To style this item provide CSS for:
|
8 | 8 | * #cookie-popup (bounding <div>)
|
9 | 9 | * p.cookie-msg (message string <p>)
|
10 |
| - * p.cookie-btn (<p> containing close button) |
11 |
| - * p.cookie-btn button (close <button> itself) |
| 10 | + * p.cookie-btn (<p> containing accept/reject buttons) |
| 11 | + * p.cookie-btn button (accept/reject buttons) |
| 12 | + * #cookie-consent-reject-btn (reject button) |
| 13 | + * #cookie-consent-accept-btn (accept button) |
12 | 14 | */
|
13 | 15 |
|
14 |
| -var CookieConsent = { |
15 |
| - exec: function() { |
16 |
| - let cookieName = 'dd_inhibit_cookie_consent'; |
17 |
| - if ( Cookie.isSet(cookieName) ) { |
18 |
| - return; |
19 |
| - } |
20 |
| - $(document.body).prepend( |
21 |
| - '<div id="cookie-popup" class="container-fluid">' |
22 |
| - + '<p class="cookie-msg">This website uses a minimum number of cookies. ' |
23 |
| - + 'There are no trackers or advertising cookies. ' |
24 |
| - + '<a href="/cookies">More info</a>.' |
25 |
| - + '</p>' |
26 |
| - + '<p class="cookie-btn"><button id="cookie-close-btn">Dismiss</button></p>' |
27 |
| - + '</div>' |
28 |
| - ); |
29 |
| - $('#cookie-close-btn').click(function() { |
30 |
| - Cookie.set(cookieName, "dismissed", 91); // expires in apx 3 mths |
31 |
| - $('#cookie-popup').hide(); |
| 16 | +$( function() { |
| 17 | + |
| 18 | + const cookieName = 'dd-base--cookies-accepted'; |
| 19 | + const sessionCookieName = 'dd-base--cookie-reject-session'; |
| 20 | + const optOutPara = '#cookie-consent--opt-out-text'; |
| 21 | + const messageHTMLPath = '/assets/scripts/includes/cookie-consent-msg.html'; |
| 22 | + |
| 23 | + // Remove redundant cookies |
| 24 | + Cookie.delete('cookieconsent_status'); |
| 25 | + Cookie.delete('dd_inhibit_cookie_consent'); |
| 26 | + Cookie.delete('dd_flash_1'); |
| 27 | + |
| 28 | + if ( Cookie.isSet(cookieName) ) { |
| 29 | + // User has accepted cookies: add opt-out link to footer |
| 30 | + const revokeBtn = '#cookie-consent--revoke'; |
| 31 | + $(optOutPara).css('display', 'block'); |
| 32 | + $(revokeBtn).on('click', function() { |
| 33 | + Cookie.delete(cookieName); |
| 34 | + location.reload(true); |
32 | 35 | });
|
33 | 36 | }
|
34 |
| -} |
35 | 37 |
|
36 |
| -$( function() { |
37 |
| - CookieConsent.exec(); |
| 38 | + else if ( sessionStorage[sessionCookieName] !== '1' ) { |
| 39 | + // No cookie decision recorded: display pop-up message |
| 40 | + $(document.body).prepend('<div id="cookie-message"></div>'); |
| 41 | + $('#cookie-message').load( |
| 42 | + messageHTMLPath, |
| 43 | + function (response, status, jqHXR) { |
| 44 | + |
| 45 | + $('#cookie-consent-accept-btn').click(function() { |
| 46 | + Cookie.set(cookieName, "1", 182); // expires in apx 6 mths |
| 47 | + $('#cookie-popup').fadeOut(); |
| 48 | + $(optOutPara).css('display', 'block'); |
| 49 | + location.reload(true); |
| 50 | + }); |
| 51 | + |
| 52 | + $('#cookie-consent-reject-btn').click(function() { |
| 53 | + Cookie.delete(cookieName); |
| 54 | + sessionStorage[sessionCookieName] = '1'; |
| 55 | + $('#cookie-popup').fadeOut(); |
| 56 | + location.reload(true); |
| 57 | + }); |
| 58 | + |
| 59 | + $(window).on('scroll', function() { |
| 60 | + |
| 61 | + let documentHeight = document.body.scrollHeight; |
| 62 | + let currentScroll = window.scrollY + window.innerHeight; |
| 63 | + // When the user is [modifier]px from the bottom, fire the event. |
| 64 | + let pageEndDelta = 150; |
| 65 | + if(currentScroll + pageEndDelta > documentHeight) { |
| 66 | + // at end: hide the message |
| 67 | + console.log('At end'); |
| 68 | + if ($('#cookie-popup').css('display') !== 'none') { |
| 69 | + console.log('hiding') |
| 70 | + $('#cookie-popup').fadeOut(); |
| 71 | + } |
| 72 | + } |
| 73 | + else { |
| 74 | + // not at end |
| 75 | + if ($('#cookie-popup').css('display') === 'none') { |
| 76 | + console.log('showing') |
| 77 | + $('#cookie-popup').fadeIn(); |
| 78 | + } |
| 79 | + } |
| 80 | + }); |
| 81 | + } |
| 82 | + ); |
| 83 | + } |
| 84 | + |
38 | 85 | });
|
0 commit comments