Skip to content

Instantly share code, notes, and snippets.

@DavidQL
Created January 7, 2011 19:53
Show Gist options
  • Save DavidQL/770003 to your computer and use it in GitHub Desktop.
Save DavidQL/770003 to your computer and use it in GitHub Desktop.
function setFacebookLike() {
$('html').attr("xmlns:og","http://www.facebook.com/2008/fbml").attr("xmlns:fb","http://www.facebook.com/2008/fbml");
// Remove previously created FB like elements -- if they exist -- so they can be re-added after AJAX pagination
$('.fb-recommend').remove();
$('#fb-root').empty();
// Build and inject Like button
$('ul.posts a').each(function() {
var fb_url = location.href.split('/')[0] + '//' + location.href.split('/')[2] + $(this).attr('href'),
fb_like = '<div class="fb_recommend"><fb:like href="'+fb_url+'" layout="standard" show_faces="false" action="recommend" colorscheme="light"></fb:like></div>';
$(this).parent().next().after(fb_like);
});
// Load in FB javascript SDK
$('body').append('<div id="fb-root"></div>');
window.fbAsyncInit = function() {
FB.init({appId: 'your_app_ID', status: true, cookie: true, xfbml: true});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
}
setFacebookLike();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment