mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Updated Giscus example to support theme change without reload
This commit is contained in:
parent
6816aa8cd0
commit
e6bcb8100f
@ -74,7 +74,17 @@ calling the `super()` function at the beginning of the block:
|
|||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
var ref = document.querySelector("[data-md-component=palette]")
|
var ref = document.querySelector("[data-md-component=palette]")
|
||||||
ref.addEventListener("change", function() {
|
ref.addEventListener("change", function() {
|
||||||
location.reload()
|
var palette = __md_get("__palette")
|
||||||
|
if (palette && typeof palette.color === "object") {
|
||||||
|
var theme = palette.color.scheme === "slate" ? "dark" : "light"
|
||||||
|
|
||||||
|
/* Instruct Giscus to change theme */
|
||||||
|
var frame = document.querySelector(".giscus-frame")
|
||||||
|
frame.contentWindow.postMessage(
|
||||||
|
{ giscus: { setConfig: { theme } } },
|
||||||
|
"https://giscus.app"
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
@ -6,5 +6,5 @@
|
|||||||
{{ super() }}
|
{{ super() }}
|
||||||
<h2 id="__comments">{{ lang.t("meta.comments") }}</h2>
|
<h2 id="__comments">{{ lang.t("meta.comments") }}</h2>
|
||||||
<script src="https://giscus.app/client.js" data-repo="squidfunk/mkdocs-material" data-repo-id="MDEwOlJlcG9zaXRvcnk1MDYxNzQyOA==" data-category="_" data-category-id="DIC_kwDOAwRcVM4CAtJY" data-mapping="pathname" data-reactions-enabled="1" data-emit-metadata="1" data-theme="light" data-lang="en" crossorigin="anonymous" async></script>
|
<script src="https://giscus.app/client.js" data-repo="squidfunk/mkdocs-material" data-repo-id="MDEwOlJlcG9zaXRvcnk1MDYxNzQyOA==" data-category="_" data-category-id="DIC_kwDOAwRcVM4CAtJY" data-mapping="pathname" data-reactions-enabled="1" data-emit-metadata="1" data-theme="light" data-lang="en" crossorigin="anonymous" async></script>
|
||||||
<script>var giscus,palette=__md_get("__palette");palette&&"object"==typeof palette.color&&"slate"===palette.color.scheme&&(giscus=document.querySelector("script[src*=giscus]")).setAttribute("data-theme","dark"),document.addEventListener("DOMContentLoaded",function(){document.querySelector("[data-md-component=palette]").addEventListener("change",function(){location.reload()})})</script>
|
<script>var giscus,palette=__md_get("__palette");palette&&"object"==typeof palette.color&&"slate"===palette.color.scheme&&(giscus=document.querySelector("script[src*=giscus]")).setAttribute("data-theme","dark"),document.addEventListener("DOMContentLoaded",function(){document.querySelector("[data-md-component=palette]").addEventListener("change",function(){var e=__md_get("__palette");e&&"object"==typeof e.color&&(e="slate"===e.color.scheme?"dark":"light",document.querySelector(".giscus-frame").contentWindow.postMessage({giscus:{setConfig:{theme:e}}},"https://giscus.app"))})})</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -57,7 +57,17 @@
|
|||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
var ref = document.querySelector("[data-md-component=palette]")
|
var ref = document.querySelector("[data-md-component=palette]")
|
||||||
ref.addEventListener("change", function() {
|
ref.addEventListener("change", function() {
|
||||||
location.reload()
|
var palette = __md_get("__palette")
|
||||||
|
if (palette && typeof palette.color === "object") {
|
||||||
|
var theme = palette.color.scheme === "slate" ? "dark" : "light"
|
||||||
|
|
||||||
|
/* Instruct Giscus to change theme */
|
||||||
|
var frame = document.querySelector(".giscus-frame")
|
||||||
|
frame.contentWindow.postMessage(
|
||||||
|
{ giscus: { setConfig: { theme } } },
|
||||||
|
"https://giscus.app"
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user