_includes/comments/disqus.html in jekyll-theme-chirpy-7.1.1 vs _includes/comments/disqus.html in jekyll-theme-chirpy-7.2.0

- old
+ new

@@ -1,40 +1,27 @@ -<!-- The Disqus lazy loading. --> - -<div id="disqus_thread"> - <p class="text-center text-muted small">Comments powered by <a href="https://disqus.com/">Disqus</a>.</p> -</div> - -<script type="text/javascript"> +<script> var disqus_config = function () { this.page.url = '{{ page.url | absolute_url }}'; this.page.identifier = '{{ page.url }}'; }; - {%- comment -%} Lazy loading {%- endcomment -%} - var disqus_observer = new IntersectionObserver( - function (entries) { - if (entries[0].isIntersecting) { - (function () { - var d = document, - s = d.createElement('script'); - s.src = 'https://{{ site.comments.disqus.shortname }}.disqus.com/embed.js'; - s.setAttribute('data-timestamp', +new Date()); - (d.head || d.body).appendChild(s); - })(); + function addDisqus() { + let disqusThread = document.createElement('div'); + let paragraph = document.createElement('p'); - disqus_observer.disconnect(); - } - }, - { threshold: [0] } - ); + disqusThread.id = 'disqus_thread'; + paragraph.className = 'text-center text-muted small'; + paragraph.innerHTML = 'Comments powered by <a href="https://disqus.com/">Disqus</a>.'; + disqusThread.appendChild(paragraph); - disqus_observer.observe(document.getElementById('disqus_thread')); + const footer = document.querySelector('footer'); + footer.insertAdjacentElement("beforebegin", disqusThread); + } {%- comment -%} Auto switch theme {%- endcomment -%} - function reloadDisqus() { - if (event.source === window && event.data && event.data.direction === ModeToggle.ID) { + function reloadDisqus(event) { + if (event.source === window && event.data && event.data.id === Theme.ID) { {%- comment -%} Disqus hasn't been loaded {%- endcomment -%} if (typeof DISQUS === 'undefined') { return; } @@ -42,9 +29,29 @@ DISQUS.reset({ reload: true, config: disqus_config }); } } } - if (document.getElementById('mode-toggle')) { - window.addEventListener('message', reloadDisqus); + addDisqus(); + + if (Theme.switchable) { + addEventListener('message', reloadDisqus); } + + {%- comment -%} Lazy loading {%- endcomment -%} + var disqusObserver = new IntersectionObserver( + function (entries) { + if (entries[0].isIntersecting) { + var d = document, + s = d.createElement('script'); + s.src = 'https://{{ site.comments.disqus.shortname }}.disqus.com/embed.js'; + s.setAttribute('data-timestamp', +new Date()); + (d.head || d.body).appendChild(s); + + disqusObserver.disconnect(); + } + }, + { threshold: [0] } + ); + + disqusObserver.observe(document.getElementById('disqus_thread')); </script>