Vulcan/lib/gravatar.js
shaialon 59f8f0411e Add a default
Add a default and check for support of devicePixelRatio
2014-09-26 19:40:31 +03:00

24 lines
No EOL
896 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.
size = size ? size : 80; // Default size to 80.
return window.devicePixelRatio ? Math.ceil(size * Math.max(1, window.devicePixelRatio)) : size; // If devicePixelRation Available, check for retina
}
options.s = retinizeSize(options.s);
var params = _.map(options, function(val, key) { return key + "=" + val;}).join('&');
if (params !== '')
url += '?' + params;
return url;
}
};