我有一个 tumblr 博客,每个帖子都添加了 facebook 评论。
我也在使用infiniteScroll。
当浏览器滚动并且内容滚动时,一切都必须再次初始化,那么我该如何重新初始化 facebook 评论呢?
这是我的代码和无限滚动的回调
function initialiseDescriptions(){
$(".description").each(function(){
$(this).click(function(){
//alert();
var postId = $(this).find(".id")[0].value;
$.openDOMWindow({
windowSourceID:'#post-' + postId,
windowPadding:20,
windowBGColor:'#fff',
overlayOpacity: 60,
borderSize:'0',
height:710,
width: 410,
anchoredSelector:'.defaultDOMWindow'
});
return false;
})
});
//Pretty sure I need to reinitialize facebook comments in here but the following code doesn't work
$("<div id='fb-root'></div>'.appendTo("body");
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
}
$(window).load(function () {
initialiseDescriptions();
var $content = $('#content');
if($content.infinitescroll) {
$content.masonry({
itemSelector: '.posts',
//columnWidth: 235,
isAnimated: true
}),
$content.infinitescroll({
navSelector : 'div#pagination',
nextSelector : 'div#pagination div#nextPage a',
itemSelector : '.posts',
loading: {
finishedMsg: '',
img: 'http://static.tumblr.com/dbek3sy/pX1lrx8xv/ajax-loader.gif'
},
bufferPx : 500,
debug : false,
},
// call masonry as a callback.
function( newElements ) {
var $newElems = $( newElements );
$newElems.hide();
// ensure that images load before adding to masonry layout
$newElems.imagesLoaded(function(){
$content.masonry( 'appended',
$newElems, true,
function(){$newElems.fadeIn();}
);
initialiseDescriptions();
});
});
}else{
$content.masonry({
itemSelector: '.posts',
//columnWidth: 235,
isAnimated: true
});
}
});