Skip to content

Instantly share code, notes, and snippets.

@Mallinanga
Created June 4, 2013 19:42
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 Mallinanga/5708892 to your computer and use it in GitHub Desktop.
Save Mallinanga/5708892 to your computer and use it in GitHub Desktop.
#jquery Facebook like & share counts
(function ($) {
$.fn.fblikecount = function (options) {
var defaults = {
baseUrl: 'http://graph.facebook.com/?ids='
// Likes
// baseUrl: 'http://graph.facebook.com/
};
var options = $.extend(defaults, options);
var count = 0;
return this.each(function () {
var $this = $(this);
$this.hide();
var objLink = $(this).attr('title');
if (objLink.indexOf('http') === 0) {
$.getJSON(defaults.baseUrl + objLink + '&callback=?', function (json) {
if (json[objLink] && json[objLink].shares) {
$this.html(json[objLink].shares);
$this.show();
}
// Likes
// if (json[objLink] && json[objLink].likes) {
// $this.html(json[objLink].likes);
// $this.show();
// }
// Shares & Comments
// if (json[objLink] && json[objLink].shares) {
// $this.append('likes: ' + json[objLink].shares);
// }
// if (json[objLink] && json[objLink].comments) {
// $this.append(' comments: ' + json[objLink].comments);
// }
// $this.show();
});
}
});
}
})(jQuery);
// <span class="likebox" title="http://www.apple.com"></span>
// <span class="likebox" title="myfanpage"></span>
// $('span.likebox').fblikecount();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment