Skip to content

Instantly share code, notes, and snippets.

@Buildstarted
Created May 15, 2012 02:51
Show Gist options
  • Save Buildstarted/2698743 to your computer and use it in GitHub Desktop.
Save Buildstarted/2698743 to your computer and use it in GitHub Desktop.
gravatarInfo for JabbR
(function ($) {
function getGravatarInfo(hash, callback) {
console.log(hash);
var url = "http://en.gravatar.com/" + hash + ".json?callback=?";
$.getJSON(url, function (result) {
if (result.entry[0]) {
result = result.entry[0];
callback(result);
}
});
}
console.log("attaching event handlers");
$(document).on("click", "img.gravatar", function (e) {
var image = $(this);
var currentInfo = image.siblings('div.gravatar-info');
if (currentInfo.length) {
if (currentInfo.css("display") == "none") {
currentInfo.show(100);
} else {
currentInfo.hide(100);
}
} else {
var url = document.createElement('a');
url.href = $(this).attr("src");
var hash = url.pathname.split('/')[2];
if (hash) {
var info = new gi(hash);
info.getInfo(function(result) {
//console.log(result);
var template = $('#new-user-gravatarInfo').tmpl(result);
template.appendTo(image.closest("li.user")).show(100);
});
}
}
});
var gi = window.gravatarInfo = function (hash) {
return new gi.fn.init(hash);
};
gi.fn = gi.prototype = {
hash: null,
getInfo: function (callback) {
getGravatarInfo(this.hash, callback);
},
init: function (hash) {
this.hash = hash;
return this;
}
};
gi.fn.init.prototype = gi.fn;
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment