|
1 | | -<!-- |
2 | | - The Disqus lazy loading. |
3 | | ---> |
| 1 | +<!-- The Disqus lazy loading. --> |
4 | 2 | <div id="disqus_thread" class="pt-2 pb-2"> |
5 | | - <p class="text-center text-muted small"> |
6 | | - Comments powered by <a href="https://disqus.com/">Disqus</a>. |
7 | | - </p> |
| 3 | + <p class="text-center text-muted small">Comments powered by <a href="https://disqus.com/">Disqus</a>.</p> |
8 | 4 | </div> |
9 | 5 |
|
10 | 6 | <script type="text/javascript"> |
11 | | - |
12 | 7 | var disqus_config = function () { |
13 | 8 | this.page.url = '{{ page.url | absolute_url }}'; |
14 | 9 | this.page.identifier = '{{ page.url }}'; |
15 | 10 | }; |
16 | 11 |
|
17 | 12 | /* Lazy loading */ |
18 | | - var disqus_observer = new IntersectionObserver(function (entries) { |
19 | | - if(entries[0].isIntersecting) { |
| 13 | + var disqus_observer = new IntersectionObserver( |
| 14 | + function (entries) { |
| 15 | + if (entries[0].isIntersecting) { |
20 | 16 | (function () { |
21 | | - var d = document, s = d.createElement('script'); |
22 | | - s.src = 'https://{{ site.comments.disqus.shortname }}.disqus.com/embed.js'; |
23 | | - s.setAttribute('data-timestamp', +new Date()); |
24 | | - (d.head || d.body).appendChild(s); |
| 17 | + var d = document, |
| 18 | + s = d.createElement('script'); |
| 19 | + s.src = 'https://{{ site.comments.disqus.shortname }}.disqus.com/embed.js'; |
| 20 | + s.setAttribute('data-timestamp', +new Date()); |
| 21 | + (d.head || d.body).appendChild(s); |
25 | 22 | })(); |
26 | 23 |
|
27 | 24 | disqus_observer.disconnect(); |
28 | | - } |
29 | | - }, { threshold: [0] }); |
| 25 | + } |
| 26 | + }, |
| 27 | + { threshold: [0] } |
| 28 | + ); |
30 | 29 |
|
31 | 30 | disqus_observer.observe(document.querySelector('#disqus_thread')); |
32 | 31 |
|
33 | 32 | /* Auto switch theme */ |
34 | 33 | function reloadDisqus() { |
35 | | - if (event.source === window && event.data && |
36 | | - event.data.direction === ModeToggle.ID) { |
| 34 | + if (event.source === window && event.data && event.data.direction === ModeToggle.ID) { |
37 | 35 | /* Disqus hasn't been loaded */ |
38 | | - if (typeof DISQUS === "undefined") { |
| 36 | + if (typeof DISQUS === 'undefined') { |
39 | 37 | return; |
40 | 38 | } |
41 | 39 |
|
|
45 | 43 | } |
46 | 44 | } |
47 | 45 |
|
48 | | - const modeToggle = document.querySelector(".mode-toggle"); |
49 | | - |
50 | | - if (typeof modeToggle !== "undefined") { |
51 | | - window.addEventListener("message", reloadDisqus); |
| 46 | + if (document.querySelector('.mode-toggle')) { |
| 47 | + window.addEventListener('message', reloadDisqus); |
52 | 48 | } |
53 | | - |
54 | 49 | </script> |
0 commit comments