Skip to content

Commit 8466b62

Browse files
toggle giscus as soon as it loads
i did see the iframe query fail once, but was unable to repro otherwise this seems to be reliable
1 parent e5c52c5 commit 8466b62

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/resources/formats/html/giscus/giscus.ejs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,15 @@
1313
<%- giscus.loading ? `data-loading=${giscus.loading}` : '' %>
1414
async>
1515
</script>
16+
<script type="application/javascript">
17+
window.document.addEventListener("DOMContentLoaded", function (event) {
18+
var giscusIframe = window.document.querySelector('iframe.giscus-frame');
19+
giscusIframe.addEventListener("load", function() {
20+
window.setTimeout(() => {
21+
window.toggleGiscusIfUsed(window.hasAlternateSentinel(), authorPrefersDark);
22+
}, 100);
23+
});
24+
});
25+
</script>
1626
<input type="hidden" id="giscus-base-theme" value="<%- giscus.baseTheme %>">
1727
<input type="hidden" id="giscus-alt-theme" value="<%- giscus.altTheme %>">

src/resources/formats/html/templates/quarto-html-before-body.ejs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@
188188
toggleGiscusIfUsed(toAlternate, darkModeDefault);
189189
};
190190
191+
window.toggleGiscusIfUsed = toggleGiscusIfUsed;
192+
191193
<% if (respectUserColorScheme) { %>
192194
queryPrefersDark.addEventListener("change", e => {
193195
if(window.localStorage.getItem("quarto-color-scheme") !== null)

0 commit comments

Comments
 (0)