Skip to content

Commit

Permalink
fix(js): Changed disqus comment counter load method. Closes #35
Browse files Browse the repository at this point in the history
  • Loading branch information
oswaldoacauan committed May 26, 2014
1 parent 248bd2a commit 48a5df7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
27 changes: 22 additions & 5 deletions src/assets/js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,29 @@
}
});
}
};

var _loadDisqusCounter = function() {
if(typeof DISQUSWIDGETS === 'object') {
DISQUSWIDGETS = undefined;
var countjs = $html.find('head script[src*="disqus.com/count.js"]').remove();
$('<script async type="text/javascript">').attr({
src: countjs.attr('src')
}).appendTo('head');
var newScript = document.createElement("script"),
countScript = $html.find('head script[src*="disqus.com/count-data.js"]').remove(),
countSrc = countScript.get(0).src.split('?')[0],
posts = $html.find('[data-disqus-identifier]'),
postsArr = [];

posts.each(function(i, el) {
postsArr.push('1=' + encodeURIComponent($(el).data('disqus-identifier')));
});
postsArr.sort();

if(postsArr.length) {
newScript.async = true
newScript.src = countSrc + '?' + postsArr.join("&");

$html.find('head').append(newScript);

DISQUSWIDGETS.getCount();
}
}
};

Expand All @@ -75,6 +91,7 @@
}

_resetDisqus();
_loadDisqusCounter();

$('[data-load-image]', $content).each(function() {
ImageLoader.load($(this));
Expand Down
2 changes: 1 addition & 1 deletion src/partials/post/list.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</li>
{{/if}}
<li class="post-item-meta-item">
<a href="{{url}}#disqus_thread" data-pjax data-disqus-identifier="{{id}}"></a>
<a href="{{url}}#disqus_thread" data-pjax data-disqus-identifier="{{id}}">Comments</a>
</li>
</ul>
</footer>
Expand Down
2 changes: 1 addition & 1 deletion src/post.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</li>
{{/if}}
<li class="post-meta-item">
<a href="#disqus_thread" data-disqus-identifier="{{id}}"></a>
<a href="#disqus_thread" data-disqus-identifier="{{id}}">Comments</a>
</li>
</ul>
<h1 itemprop="name headline" class="post-title"><a href="{{url}}" itemprop="url" data-pjax title="{{{title}}}">{{{title}}}</a></h1>
Expand Down

0 comments on commit 48a5df7

Please sign in to comment.