Wallet/src/js/directives/gravatar.js

32 lines
1 KiB
JavaScript
Raw Normal View History

2016-09-13 17:39:01 -03:00
'use strict';
angular.module('copayApp.directives')
2018-07-09 18:22:11 +02:00
.directive('gravatar', function(md5, $http) {
2016-09-13 17:39:01 -03:00
return {
restrict: 'AE',
replace: true,
scope: {
name: '@',
height: '@',
width: '@',
2018-07-09 18:22:11 +02:00
email: '@',
url: '@'
2016-09-13 17:39:01 -03:00
},
link: function(scope, el, attr) {
if (typeof scope.email === "string") {
scope.emailHash = md5.createHash(scope.email.toLowerCase() || '');
2018-07-09 18:22:11 +02:00
var req = {
method: 'GET',
url: 'https://secure.gravatar.com/'+scope.emailHash+'.json',
};
scope.url = 'img/contact-placeholder.svg';
$http(req).then(function (response) {
scope.url = 'https://secure.gravatar.com/avatar/'+scope.emailHash+'.jpg?s='+scope.width+'&d=mm';
}, function (error) {
scope.url = 'img/contact-placeholder.svg';
});
}
2016-09-13 17:39:01 -03:00
},
2018-07-09 18:22:11 +02:00
template: '<img class="gravatar" alt="{{ name }}" height="{{ height }}" width="{{ width }}" src="{{ url }}">'
2016-11-01 14:56:53 -04:00
};
2016-09-13 17:39:01 -03:00
});