45 lines
No EOL
1.2 KiB
JavaScript
45 lines
No EOL
1.2 KiB
JavaScript
/**
|
|
* An element which displays an avatar for the given avatar data.
|
|
*/
|
|
angular.module('quay').directive('avatar', function () {
|
|
var directiveDefinitionObject = {
|
|
priority: 0,
|
|
templateUrl: '/static/directives/avatar.html',
|
|
replace: false,
|
|
transclude: true,
|
|
restrict: 'C',
|
|
scope: {
|
|
'data': '=data',
|
|
'size': '=size'
|
|
},
|
|
controller: function($scope, $element, AvatarService, Config, UIService) {
|
|
$scope.AvatarService = AvatarService;
|
|
$scope.Config = Config;
|
|
$scope.isLoading = true;
|
|
$scope.hasGravatar = false;
|
|
$scope.loadGravatar = false;
|
|
|
|
$scope.imageCallback = function(r) {
|
|
$scope.isLoading = false;
|
|
$scope.hasGravatar = r;
|
|
};
|
|
|
|
$scope.$watch('size', function(size) {
|
|
size = size * 1 || 16;
|
|
$scope.fontSize = (size - 4) + 'px';
|
|
$scope.lineHeight = size + 'px';
|
|
});
|
|
|
|
$scope.$watch('data', function(data) {
|
|
if (!data) { return; }
|
|
|
|
$scope.loadGravatar = Config.AVATAR_KIND == 'gravatar' &&
|
|
(data.kind == 'user' || data.kind == 'org');
|
|
|
|
$scope.isLoading = $scope.loadGravatar;
|
|
$scope.hasGravatar = false;
|
|
});
|
|
}
|
|
};
|
|
return directiveDefinitionObject;
|
|
}); |