1
0
mirror of https://github.com/cotes2020/jekyll-theme-chirpy.git synced 2025-12-18 05:41:31 +00:00

Replace Disqus lazy loading plugin with native JS

This commit is contained in:
Cotes Chung
2021-09-14 20:45:17 +08:00
parent 603705f20e
commit 2acf14ecf0
2 changed files with 22 additions and 22 deletions

View File

@@ -1,25 +1,33 @@
<!--
The Disqus lazy loading.
Powered by: <https://github.com/osvaldasvalutis/disqusLoader.js>
-->
<div id="disqus" class="pt-2 pb-2">
<p class="text-center text-muted small pb-5">
<div id="disqus_thread" class="pt-2 pb-2">
<p class="text-center text-muted small mb-5">
Comments powered by <a href="https://disqus.com/">Disqus</a>.
</p>
</div>
<script src="{{ '/assets/js/lib/jquery.disqusloader.min.js' | relative_url }}"></script>
<script>
const options = {
scriptUrl: '//{{ site.disqus.shortname }}.disqus.com/embed.js',
disqusConfig: function() {
this.page.title = '{{ page.title }}';
this.page.url = '{{ page.url | absolute_url }}';
this.page.identifier = '{{ page.url }}';
}
<script type="text/javascript">
var disqus_config = function () {
this.page.url = '{{ page.url | absolute_url }}';
this.page.identifier = '{{ page.url }}';
};
$.disqusLoader('#disqus', options);
/* Lazy loading */
var disqus_observer = new IntersectionObserver(function (entries) {
if(entries[0].isIntersecting) {
(function () {
var d = document, s = d.createElement('script');
s.src = 'https://{{ site.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.querySelector("#disqus_thread"));
</script>