web/_includes/comments/disqus.html

51 lines
1.5 KiB
HTML
Raw Permalink Normal View History

<!-- 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>
2019-09-30 15:38:41 +03:00
</div>
<script type="text/javascript">
var disqus_config = function () {
this.page.url = '{{ page.url | absolute_url }}';
this.page.identifier = '{{ page.url }}';
};
2024-04-28 22:25:26 +03:00
{%- 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);
})();
disqus_observer.disconnect();
}
},
{ threshold: [0] }
);
2019-09-30 15:38:41 +03:00
disqus_observer.observe(document.getElementById('disqus_thread'));
2021-09-14 15:45:17 +03:00
2024-04-28 22:25:26 +03:00
{%- comment -%} Auto switch theme {%- endcomment -%}
2021-09-14 15:45:17 +03:00
function reloadDisqus() {
if (event.source === window && event.data && event.data.direction === ModeToggle.ID) {
2024-04-28 22:25:26 +03:00
{%- comment -%} Disqus hasn't been loaded {%- endcomment -%}
if (typeof DISQUS === 'undefined') {
return;
}
if (document.readyState == 'complete') {
DISQUS.reset({ reload: true, config: disqus_config });
}
2021-09-14 15:45:17 +03:00
}
}
if (document.getElementById('mode-toggle')) {
window.addEventListener('message', reloadDisqus);
2021-09-14 15:45:17 +03:00
}
2021-01-18 18:27:43 +03:00
</script>