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 the data-callback attribute #854

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions ADVANCED-USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,19 @@ your website. Make sure that your users are aware of this.

For more details, see [creating new themes][creating-new-themes].

### `data-callback`

The callback function will be invoked after loading the `iframe`.

```html
<script src="https://giscus.app/client.js"
data-repo="giscus/giscus"
...
data-callback="console.log('iframe loaded')"
...>
</script>
```

## `<meta>` tags

Your website can define additional `<meta>` tags to help giscus gather the
Expand Down
2 changes: 2 additions & 0 deletions client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
const locale = attributes.lang ? `/${attributes.lang}` : '';
const src = `${giscusOrigin}${locale}/widget?${new URLSearchParams(params)}`;
const loading = attributes.loading === 'lazy' ? 'lazy' : undefined;
const onload = attributes.callback ?? undefined;

// Set up iframe element
const iframeElement = document.createElement('iframe');
Expand All @@ -98,6 +99,7 @@
allow: 'clipboard-write',
src,
loading,
onload,
};
Object.entries(iframeAttributes).forEach(
([key, value]) => value && iframeElement.setAttribute(key, value),
Expand Down