orestbida / cookieconsent

:cookie: Simple cross-browser cookie-consent plugin written in vanilla js
https://playground.cookieconsent.orestbida.com/
MIT License
4.08k stars 416 forks source link

[Feat]: Expose the event that triggered onModalShow/onModalHide callback function #707

Open peaemaye opened 4 months ago

peaemaye commented 4 months ago

Description

When using the onModalShow() callback function it can be useful to know what triggered it. An easy way to achieve this is to expose the event that triggered the callback allowing us to check the event.target or other info.

In may case I wanted to auto-expand a third party services section if it was opened from a static button using: data-cc='show-preferencesModal', but not if it was opened from the button in the standard consent modal.

Proposed solution

See PR #706

Additional details

I've put together a quick StackBlitz to show this in action: https://stackblitz.com/edit/stackblitz-starters-9caf9y?file=index.js