Skip to content

Instantly share code, notes, and snippets.

@Takazudo
Created August 26, 2011 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Takazudo/1173316 to your computer and use it in GitHub Desktop.
Save Takazudo/1173316 to your computer and use it in GitHub Desktop.
$.fn.initFbComments
.mod-fbcomments{
float:left;
margin:5px;
}
<script src="https://raw.github.com/SlexAxton/yepnope.js/master/yepnope.js"></script>
<button id="button">Boom</button>
<div id="root"></div>
var src = [
'<div class="mod-fbcomments"><fb:comments href="example.com" num_posts="1" width="250"></fb:comments></div>',
'<div class="mod-fbcomments"><fb:comments href="yahoo.com" num_posts="1" width="250"></fb:comments></div>'
].join('');
$.fn.initFbComments = function(){
var found = false;
this.each(function(){
if( $('.mod-fbcomments', this).size() !== 0 ){
found = true;
return;
}
});
if(found){
yepnope.loader.load('http://connect.facebook.net/en_US/all.js#xfbml=1')
}
return this;
};
$(function(){
var $root = $('#root');
$('#button').click(function(){
$root.empty().append(src).initFbComments();
});
});
name: $.fn.initFbComments
description: append facebook comments dynamically. http://jsfiddle.net/gh/gist/jQuery/1.6.2/1173316/ https://gist.github.com/1173316 http://developers.facebook.com/docs/reference/plugins/comments/
authors:
- Takeshi Takatsudo
normalize_css: no
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment