web/_includes/comments/disqus.html

58 lines
1.7 KiB
HTML
Raw Permalink Normal View History

<script>
var disqus_config = function () {
this.page.url = '{{ page.url | absolute_url }}';
this.page.identifier = '{{ page.url }}';
};
function addDisqus() {
let disqusThread = document.createElement('div');
let paragraph = document.createElement('p');
2019-09-30 15:38:41 +03:00
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);
const footer = document.querySelector('footer');
footer.insertAdjacentElement("beforebegin", disqusThread);
}
2021-09-14 15:45:17 +03:00
2024-04-28 22:25:26 +03:00
{%- comment -%} Auto switch theme {%- endcomment -%}
function reloadDisqus(event) {
if (event.source === window && event.data && event.data.id === Theme.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
}
}
addDisqus();
if (Theme.switchable) {
addEventListener('message', reloadDisqus);
2021-09-14 15:45:17 +03:00
}
{%- 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'));
2021-01-18 18:27:43 +03:00
</script>