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

Add class to open the cookie notice #11

Open
SvenBasePlus opened this issue May 28, 2024 · 0 comments
Open

Add class to open the cookie notice #11

SvenBasePlus opened this issue May 28, 2024 · 0 comments

Comments

@SvenBasePlus
Copy link

The wiki describes a way of using the cookie notice via the Javascript API. This method, however, has the disadvantage that, for example, a menu item created via the WordPress backend cannot have the option of opening the notice, as no onclick attribute can be added.

I currently use the workaround of integrating a script into the "Always-On Scripts" option, which places a click event listener on all links of the "open-cookie-consent" class, which calls the function defined in the wiki.

<script>
	const triggerCookiefoxModal = () => {
        const modalTrigger = document.querySelectorAll('.open-cookie-consent');

        if (modalTrigger.length > 0) {
            modalTrigger.forEach(element => {
                element.addEventListener('click', event => {
                    event.preventDefault();

                    cookiefox.api.show();
                });
            });
        }

        document.removeEventListener('cookiefox:init', triggerCookiefoxModal);
    }

    if (typeof cookiefox == "undefined") {
        document.addEventListener('cookiefox:init', triggerCookiefoxModal);
    } else {
        triggerCookiefoxModal();
    }
</script>

Would it be possible to introduce such a class as standard in the plugin?

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

1 participant