GetGravatar updated to 1.2
![]()
With an update so big that it had to skip a whole point, i'm happy to announce that GetGravatar is now updated to 1.2. Now with 100% less PHP required, and 50% less AJAX calls!
Basically, I removed the dependency on the PHP file, and integrated a couple of functions from the awesome php.js project in order to speed things up significantly.
Parameters
- fallback (string): URL to your placeholder image for if the user does not have a Gravatar. Must be an exact URL.
- avatarSize (number, 0-512): Size in pixels of the gravatar to fetch.
- avatarContainer (string): jQuery style selector of the
tag to put the gravatar in once it’s loaded. Default is "#gravatar".
- start (function): Function to run when it starts loading. Perfect place to put code for a Loading indicator.
- stop (function): Function to run when it’s done loading. Perfect place to put code to hide a Loading indicator.
Code examples:
Barebones usage:
$("#email-address").getGravatar();
Simple parameters:
$("#email-address").getGravatar({
fallback: 'http://myurl.com/images/default.png'
});
More parameters:
$("#email-address").getGravatar({
fallback: 'http://myurl.com/images/default.png',
avatarSize: 80,
avatarContainer: '#gravatar-container'
});
Specify start and stop functions
$("#email-address").getGravatar({
start: function(){
$("loading").show();
},
stop: function(){
$("loading").hide();
}
});
You can download the plugin below:
Download getgravatar-1.2.zip
ZIP Format, 41 kb
Or check it out on Github.



5 comments
Enrique Ramírez
Nov 18, 2009Just a quick note: If the input field is set to anything other than “text”, the script fails to work.
This is rather important since, if you use HTML5’s “email” attribute, the script doesn’t work at all and you’re forced to go back to the old, less semantic, “text” attribute. It does work on Mozilla (which fallbacks to a “text” type if something unknown doesn’t work), but not on webkit and am not sure about IE.
The fix should be fairly quick, though. Didn’t browse much around the .js file, but a slight edit to line 49 of the file should do the trick.
It might also be a good idea to make the script work on blur of the field. If you use the autocomplete feature of your browser, you get no gravatar. ):
Thanks so much for this script! It adds that extra “Wow” to my site. :)
(JavaScript must be enabled to view this email address)
Nov 18, 2009Enrique, Great calls all around. I think what’s preventing it from happening is that it’s specifically looking for inputs with the type of “text” to prevent it from being called on other things that wouldn’t work. I really should include other valid options.
The blur might be a good idea. I’ll have to test it. Maybe I can use onchange or something. It needs to just realize when the value has changed, rather than when a character is pressed.
Thanks for the feedback :)
seo
Dec 19, 2009Thank you;)
Nerd
Jan 10, 2010Nice plugin! gravatar makes personal pictures much easier.
Surfstick
Jan 10, 2010GetGravatar is great. Thanks a lot for this script. I’m using it on a private portfolio page.