Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to add class to body or html tag once cookie has been accepted OR rejected #69

Open
1corn opened this issue May 7, 2023 · 2 comments

Comments

@1corn
Copy link

1corn commented May 7, 2023

I am displaying the banner using position: fixed (at the bottom of the viewport) and in order for it to not hide my footer I am adding some additional padding-bottom to my main wrapper when the banner is present.

I am removing the padding once cookies have been accepted the same way I activate my Google Analytics, no problem. But there currently doesn't seem to be an easy way to to add a style when cookies are rejected - or am I missing something?

It would be great to have an option to add a class to the body after accepting/rejecting cookies or when the hasConsent cookie is already present. Something like '.cookies-eu-banner-present'.

@Alex-D
Copy link
Owner

Alex-D commented May 9, 2023

So, you want a reject callback?

You can already call hasConsent on the CookiesEuBanner instance if you want, but I have to admit that this is not the most convenient way to do it after reject button is pushed

@1corn
Copy link
Author

1corn commented May 9, 2023

Exactly, I thought there might be a better way to solve this. But maybe I'm missing something. To set a body class for every case in which the banner is not present, I currently need to look at 3 separate cases (simplified):

In case I have consent, I just do this, very easy:

new CookiesEuBanner(function () {

  body.classList.add("cookie-present");

  // (...) everything else I do when consent has been given

}, true);

If the user rejects, I do this on button press:

$('#cookies-eu-reject').on('click', function() {
  $('body').addClass('cookie-present');
});

And if the user visits the page and consent has already been rejected before, I do this:

function addCookieConditionalStyles() {
  if (cookie != null) {
    $('body').addClass('cookie-present');
  }
}

PS: Beautiful plugin, thanks for the quick reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants