Created
August 5, 2014 13:27
-
-
Save miguel-perez/99464af1272fdd1edc1f to your computer and use it in GitHub Desktop.
Disqus and smoothState.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} | |
}); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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