mirror of
https://github.com/peter-tanner/peter-tanner.github.io.git
synced 2024-12-02 21:10:17 +08:00
51 lines
1.5 KiB
HTML
51 lines
1.5 KiB
HTML
<!-- 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">
|
|
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);
|
|
})();
|
|
|
|
disqus_observer.disconnect();
|
|
}
|
|
},
|
|
{ threshold: [0] }
|
|
);
|
|
|
|
disqus_observer.observe(document.getElementById('disqus_thread'));
|
|
|
|
{%- comment -%} Auto switch theme {%- endcomment -%}
|
|
function reloadDisqus() {
|
|
if (event.source === window && event.data && event.data.direction === ModeToggle.ID) {
|
|
{%- comment -%} Disqus hasn't been loaded {%- endcomment -%}
|
|
if (typeof DISQUS === 'undefined') {
|
|
return;
|
|
}
|
|
|
|
if (document.readyState == 'complete') {
|
|
DISQUS.reset({ reload: true, config: disqus_config });
|
|
}
|
|
}
|
|
}
|
|
|
|
if (document.getElementById('mode-toggle')) {
|
|
window.addEventListener('message', reloadDisqus);
|
|
}
|
|
</script>
|