Skip to content

Commit 6fec411

Browse files
authored
fix: mode-toggle leads to Disqus loading failure (#945)
1 parent 0d9cec6 commit 6fec411

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

_includes/comments/disqus.html

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,39 @@
1-
<!--
2-
The Disqus lazy loading.
3-
-->
1+
<!-- The Disqus lazy loading. -->
42
<div id="disqus_thread" class="pt-2 pb-2">
5-
<p class="text-center text-muted small">
6-
Comments powered by <a href="https://disqus.com/">Disqus</a>.
7-
</p>
3+
<p class="text-center text-muted small">Comments powered by <a href="https://disqus.com/">Disqus</a>.</p>
84
</div>
95

106
<script type="text/javascript">
11-
127
var disqus_config = function () {
138
this.page.url = '{{ page.url | absolute_url }}';
149
this.page.identifier = '{{ page.url }}';
1510
};
1611

1712
/* Lazy loading */
18-
var disqus_observer = new IntersectionObserver(function (entries) {
19-
if(entries[0].isIntersecting) {
13+
var disqus_observer = new IntersectionObserver(
14+
function (entries) {
15+
if (entries[0].isIntersecting) {
2016
(function () {
21-
var d = document, s = d.createElement('script');
22-
s.src = 'https://{{ site.comments.disqus.shortname }}.disqus.com/embed.js';
23-
s.setAttribute('data-timestamp', +new Date());
24-
(d.head || d.body).appendChild(s);
17+
var d = document,
18+
s = d.createElement('script');
19+
s.src = 'https://{{ site.comments.disqus.shortname }}.disqus.com/embed.js';
20+
s.setAttribute('data-timestamp', +new Date());
21+
(d.head || d.body).appendChild(s);
2522
})();
2623

2724
disqus_observer.disconnect();
28-
}
29-
}, { threshold: [0] });
25+
}
26+
},
27+
{ threshold: [0] }
28+
);
3029

3130
disqus_observer.observe(document.querySelector('#disqus_thread'));
3231

3332
/* Auto switch theme */
3433
function reloadDisqus() {
35-
if (event.source === window && event.data &&
36-
event.data.direction === ModeToggle.ID) {
34+
if (event.source === window && event.data && event.data.direction === ModeToggle.ID) {
3735
/* Disqus hasn't been loaded */
38-
if (typeof DISQUS === "undefined") {
36+
if (typeof DISQUS === 'undefined') {
3937
return;
4038
}
4139

@@ -45,10 +43,7 @@
4543
}
4644
}
4745

48-
const modeToggle = document.querySelector(".mode-toggle");
49-
50-
if (typeof modeToggle !== "undefined") {
51-
window.addEventListener("message", reloadDisqus);
46+
if (document.querySelector('.mode-toggle')) {
47+
window.addEventListener('message', reloadDisqus);
5248
}
53-
5449
</script>

0 commit comments

Comments
 (0)