Skip to content

Instantly share code, notes, and snippets.

@miguel-perez
Created August 5, 2014 13:27
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguel-perez/99464af1272fdd1edc1f to your computer and use it in GitHub Desktop.
Save miguel-perez/99464af1272fdd1edc1f to your computer and use it in GitHub Desktop.
Disqus and smoothState.js
// DISQUS
var MP = MP || {};
MP.comments = {
init: function(){
"use strict";
var disqus_shortname = 'miguelperez';
(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);
})();
},
reset: function(url){
var isArticle = $('#disqus_thread').length,
hasDisqus = typeof DISQUS !== "undefined";
if( isArticle && hasDisqus ) {
DISQUS.reset({
reload: true,
config: function () {
this.page.identifier = url;
this.page.identifier = "disqus" + Math.round(Math.rand() * 100);
this.page.url = "http://miguel-perez.com" + url + "#!newthread";
}
});
} else if(isArticle) {
this.init();
}
}
};
$(document).ready(function(){
if($('#disqus_thread').length) {
MP.comments.init();
}
});
$(document).ready(function(){
var $page = $('#page'),
content = $page.smoothState({
onAfter: function(url, $container, $content) {
MP.comments.reset();
}
}).data('smoothState');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment