From 60f10bbdc67b4ffe8f078a24d40a654ffb6f1688 Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Sun, 28 Jun 2015 23:15:28 +0200 Subject: [PATCH] Load comment scripts on first click. --- _includes/comments.html | 17 ++++------------- javascripts/comments.coffee | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/_includes/comments.html b/_includes/comments.html index d40acfc..4293fc4 100644 --- a/_includes/comments.html +++ b/_includes/comments.html @@ -1,29 +1,20 @@ -
-
+
+ -
-
Loading Google+ comments…
diff --git a/javascripts/comments.coffee b/javascripts/comments.coffee index d9a8818..9a9e0f2 100644 --- a/javascripts/comments.coffee +++ b/javascripts/comments.coffee @@ -3,6 +3,26 @@ $(document).ready -> $('ul#comments-tabs li').not('.static').click -> tab_id = $(this).attr 'data-div' + service = $(this).attr 'data-service' + + switch service + when 'disqus' + # load Disqus + 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 + $(this).removeAttr 'data-service' + + when 'google' + # load Google+ + gog = document.createElement 'script' + gog.type = 'text/javascript' + gog.async = true + gog.src = '//apis.google.com/js/plusone.js' + (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild gog + $(this).removeAttr 'data-service' $('ul#comments-tabs li').removeClass 'current' $('.comments-tab').removeClass 'current'