Vulcan/lib/gravatar.js
shaialon b4a811a506 Retinize gravatar image size
Fix gravatars pixelation in retina displays an zoomed in browsers
2014-09-25 22:02:33 +03:00

23 lines
No EOL
755 B
JavaScript

// super, super simple
Gravatar = {
getGravatar: function(user, options) {
var options = options || {};
var protocol = options.secure ? 'https' : 'http';
delete options.secure;
var hash = !!user.email_hash ? user.email_hash : ''; // if hash not available, just pass empty string
var url = protocol + '://www.gravatar.com/avatar/' + hash;
function retinizeSize(size) {
// return the optimal image size for retina display or zoomed in view.
return Math.ceil(size * Math.max(1, window.devicePixelRatio));
}
options.s = retinizeSize(options.s);
var params = _.map(options, function(val, key) { return key + "=" + val;}).join('&');
if (params !== '')
url += '?' + params;
return url;
}
};