load disqus only on request
authorMichael Wallner <mike@php.net>
Wed, 6 Mar 2019 15:14:27 +0000 (16:14 +0100)
committerMichael Wallner <mike@php.net>
Wed, 6 Mar 2019 15:15:33 +0000 (16:15 +0100)
public/index.css
public/index.js
views/layout.phtml

index 69f33cc8d72f6e339f23a49fea9b6f34972a0203..c0204cdb3464ef6db258bceab1f50e84f737d12d 100644 (file)
@@ -27,6 +27,9 @@ div.page {
 div.page>* {
        margin-left: 1em;
 }
+div.page>footer {
+       margin-left: 0;
+}
 div.page>ul, div.page>div>ul {
        margin-left: 2em;
 }
@@ -247,6 +250,18 @@ li h3 a:hover {
        margin-top: 8em;
        margin-right: 2em;
 }
+#disqus_activator {
+       margin: auto;
+       width: 80%;
+       padding: 1em;
+       background-color: slategrey;
+       color: white;
+       font-size: 1em;
+       font-weight: bold;
+       border: 0;
+       border-radius: 2px;
+       box-shadow: 0 0 4px #999;
+}
 
 footer {
        font-size: smaller;
@@ -256,7 +271,11 @@ footer {
        bottom: 0;
        width: 100%;
        padding: 0;
-       margin: 0 !important;
+       transition: margin-bottom 2s ease 0.1s;
+}
+footer.hidden {
+       margin-bottom: -10em;
+       transition: margin-bottom 2s ease 0.1s;
 }
 
 footer ul {
index 8d6c506bd533a71ff70ed92b0e33f0c32f07b2bc..5f0f34f0eb9da6a0e42524c1cb2a55f32970b267 100644 (file)
@@ -231,4 +231,18 @@ $(function() {
        $("h1,h2,h3,h4,h5,h6,p,li,code,td").each(mdref.walk);
        $(window).on("hashchange", mdref.hashchange);
        mdref.hashchange();
+
+       $("#disqus_activator").on("click", function() {
+               var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
+               dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
+               (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
+       });
+       $.ajax("https://disqus.com/api/3.0/threads/details.json?thread:ident="+(disqus_identifier||"index")+"&forum=mdref&api_key=VmhVG4z5jjtY8SCaMstOjfUuwniMv43Xy9FCU9YfEzhsrl95dNz1epykXSJn8jt9"). then(function(json) {
+               if (json && json.response) {
+                       $("#disqus_activator span").text(json.response.posts);
+               }
+       });
+       setTimeout(function() {
+               $("footer").addClass("hidden");
+       }, 1);
 });
index e4d438d51e4c654aaeda248225ab85d6d1911c69..e49d520fe8a9c66509d00ab6f77c69bc9e85ac31 100644 (file)
                        <?php include __DIR__."/index.phtml" ?>
                <?php endif; ?>
 
-               <?php if (@$_SERVER["SERVER_NAME"] != "localhost") : ?>
-
-                       <div id="disqus_thread"></div>
+                       <div id="disqus_thread"><button id="disqus_activator">Show <span> </span> Comment(s)</button></div>
                        <script>
                                var disqus_shortname = 'mdref';
                                var disqus_identifier = '<?=$ref?>';
-                               (function() {
-                                       var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
-                                       dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
-                                       (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
-                               })();
                        </script>
-               <?php endif; ?>
 
                        <footer>
                                <?php include __DIR__."/footer.phtml" ?>