Only load disqus comments on button click
This commit is contained in:
parent
4e14faf824
commit
c2a934f566
6
layouts/partials/disqus-js-common.js
Normal file
6
layouts/partials/disqus-js-common.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
// Remove button
|
||||||
|
var disqusButton = document.getElementById('disqus-button');
|
||||||
|
disqusButton.remove();
|
||||||
|
// Un-hide comments
|
||||||
|
var disqusComments = document.getElementById('disqus-comments');
|
||||||
|
disqusComments.style.display = 'block';
|
10
layouts/partials/disqus-js-main.js
Normal file
10
layouts/partials/disqus-js-main.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
// Config
|
||||||
|
var disqus_config = function () {
|
||||||
|
};
|
||||||
|
// Build and append comments
|
||||||
|
var d = document;
|
||||||
|
var s = d.createElement('script');
|
||||||
|
s.async = true;
|
||||||
|
s.src = '//' + "{{ . }}" + '.disqus.com/embed.js';
|
||||||
|
s.setAttribute('data-timestamp', + new Date());
|
||||||
|
(d.head || d.body).appendChild(s);
|
|
@ -1,13 +1,27 @@
|
||||||
<div id="disqus-container">
|
<div id="disqus-container">
|
||||||
{{ $ctx := . }}
|
|
||||||
{{ with .Site.DisqusShortname }}
|
{{ with .Site.DisqusShortname }}
|
||||||
<button id="disqus-button" onclick="showComments()">Show comments</button>
|
<button id="disqus-button" onclick="showComments()">Show comments</button>
|
||||||
<div id="disqus-comments">
|
<div id="disqus-comments">
|
||||||
{{ if eq . "yourdiscussshortname" }}
|
{{ $isDummyName := eq . "yourdiscussshortname" }}
|
||||||
|
{{ $isServer := $.Site.IsServer }}
|
||||||
|
{{ if or $isDummyName $isServer }}
|
||||||
<p>Disqus comments are disabled.</p>
|
<p>Disqus comments are disabled.</p>
|
||||||
|
<script type="application/javascript">
|
||||||
|
function showComments() {
|
||||||
|
{{ partial "disqus-js-common.js" . | safeJS }}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
{{ template "_internal/disqus.html" $ctx }}
|
<div id="disqus_thread">
|
||||||
|
</div>
|
||||||
|
<script type="application/javascript">
|
||||||
|
function showComments() {
|
||||||
|
{{ partial "disqus-js-main.js" . | safeJS }}
|
||||||
|
{{ partial "disqus-js-common.js" . | safeJS }}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
<noscript>Enable JavaScript to view Disqus comments.</noscript>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -131,12 +131,3 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/* Disqus comments */
|
|
||||||
function showComments() {
|
|
||||||
var disqusButton = document.getElementById('disqus-button');
|
|
||||||
disqusButton.remove();
|
|
||||||
|
|
||||||
var disqusComments = document.getElementById('disqus-comments');
|
|
||||||
disqusComments.style.display = 'block';
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user