Created
May 15, 2012 02:51
-
-
Save Buildstarted/2698743 to your computer and use it in GitHub Desktop.
gravatarInfo for JabbR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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