Skip to content

Commit

Permalink
(chocolatey#195) Set Cookie on Mobile for Cookie Banner
Browse files Browse the repository at this point in the history
Recently a handful of JavaScript functions were rewritten to remove
jQuery. In the process, the script that controlled setting of the
cookie when a user clicks the "I accept" button in the cookie banner
broke. It has been adjusted slightly to take into account multiple
buttons, which allows the cookie to be set on both desktop and mobile.
  • Loading branch information
st3phhays committed Jun 10, 2022
1 parent 2f92f31 commit d69ffa2
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions js/chocolatey-alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
cookieNoticeAlert.classList.remove('d-none');
}

cookieNoticeAlert.querySelector('button').addEventListener('click', function() {
if (~location.hostname.indexOf('chocolatey.org')) {
document.cookie = cookieNoticeName + '=true; ' + setCookieExpirationNever() + 'path=/; domain=chocolatey.org;';
} else {
document.cookie = cookieNoticeName + '=true;' + setCookieExpirationNever() + 'path=/;';
}
}, false);
cookieNoticeAlert.querySelectorAll('button').forEach(function (el) {
el.addEventListener('click', function() {
if (~location.hostname.indexOf('chocolatey.org')) {
document.cookie = cookieNoticeName + '=true; ' + setCookieExpirationNever() + 'path=/; domain=chocolatey.org;';
} else {
document.cookie = cookieNoticeName + '=true;' + setCookieExpirationNever() + 'path=/;';
}
}, false);
});
}
})();

0 comments on commit d69ffa2

Please sign in to comment.