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

Allow running callbacks when button is clicked #88

Open
kdheepak opened this issue May 13, 2022 · 2 comments
Open

Allow running callbacks when button is clicked #88

kdheepak opened this issue May 13, 2022 · 2 comments

Comments

@kdheepak
Copy link

Thanks for maintaining darkmode.js.

This is a feature request. It would be nice to run some additional custom javascript code on light / dark mode toggle. For example, a user might want to toggle the theme of their comments using this:

const iframe = document.querySelector("iframe.giscus-frame");
iframe.contentWindow.postMessage({giscus: {setConfig: {theme: "dark"}}}, "https://giscus.app/");

It would be great if the constructor accepted a callback that was called in the on click handler for the button for toggling the light / dark mode.

@sandoche
Copy link
Owner

sandoche commented May 29, 2022

Hey that's a nice idea, if you have some time feel free to implement it!
I'll happily review, merge and deploy the feature.

@eugenekolo
Copy link

This works:

var darkmode = new Darkmode();
darkmode.button.addEventListener('click', () => {
        console.log("hello cb");
});

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

3 participants