Skip to content

Commit

Permalink
fix(comment): disqus doesn't follow theme mode switching
Browse files Browse the repository at this point in the history
  • Loading branch information
cotes2020 committed Nov 22, 2022
1 parent e50343b commit b0d5956
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions _includes/comments/disqus.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
};

/* Lazy loading */

var disqus_observer = new IntersectionObserver(function (entries) {
if(entries[0].isIntersecting) {
(function () {
Expand All @@ -32,23 +31,24 @@
disqus_observer.observe(document.querySelector('#disqus_thread'));

/* Auto switch theme */

function reloadDisqus() {
/* Disqus hasn't been loaded */
if (typeof DISQUS === "undefined") {
return;
}

if (document.readyState == 'complete') {
DISQUS.reset({ reload: true, config: disqus_config });
if (event.source === window && event.data &&
event.data.direction === ModeToggle.ID) {
/* Disqus hasn't been loaded */
if (typeof DISQUS === "undefined") {
return;
}

if (document.readyState == 'complete') {
DISQUS.reset({ reload: true, config: disqus_config });
}
}
}

const modeToggle = document.querySelector(".mode-toggle");

if (typeof modeToggle !== "undefined") {
/* modeToggle.addEventListener('click', reloadDisqus); // not pretty for 'color-scheme' */
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', reloadDisqus);
window.addEventListener("message", reloadDisqus);
}

</script>

0 comments on commit b0d5956

Please sign in to comment.