diff --git a/static/directives/avatar.html b/static/directives/avatar.html index 866992232..b55f0405a 100644 --- a/static/directives/avatar.html +++ b/static/directives/avatar.html @@ -4,7 +4,7 @@ + ng-image-watch="imageCallback(result)"> {{ data.name.charAt(0).toUpperCase() }} Ω diff --git a/static/js/directives/ng-image-watch.js b/static/js/directives/ng-image-watch.js index 43aac4792..7b6cde7b7 100644 --- a/static/js/directives/ng-image-watch.js +++ b/static/js/directives/ng-image-watch.js @@ -1,17 +1,20 @@ /** * Adds a ng-image-watch attribute, which is a callback invoked when the image is loaded or fails. */ -angular.module('quay').directive('ngImageWatch', function () { +angular.module('quay').directive('ngImageWatch', function ($parse) { return { restrict: 'A', - link: function postLink($scope, $element, $attr) { - $element.bind('error', function() { - $scope.$eval($attr.ngImageWatch)(false); - }); + compile: function($element, attr) { + var fn = $parse(attr['ngImageWatch']); + return function(scope, element) { + element.bind('error', function() { + fn(scope, {result: false}); + }); - $element.bind('load', function() { - $scope.$eval($attr.ngImageWatch)(true); - }); + element.bind('load', function() { + fn(scope, {result: true}); + }); + } } }; }); \ No newline at end of file diff --git a/static/js/directives/ui/avatar.js b/static/js/directives/ui/avatar.js index 18dd9bb72..80a74f8d5 100644 --- a/static/js/directives/ui/avatar.js +++ b/static/js/directives/ui/avatar.js @@ -12,7 +12,7 @@ angular.module('quay').directive('avatar', function () { 'data': '=data', 'size': '=size' }, - controller: function($scope, $element, AvatarService, Config, UIService) { + controller: function($scope, $element, AvatarService, Config, UIService, $timeout) { $scope.AvatarService = AvatarService; $scope.Config = Config; $scope.isLoading = true; @@ -20,8 +20,10 @@ angular.module('quay').directive('avatar', function () { $scope.loadGravatar = false; $scope.imageCallback = function(r) { - $scope.isLoading = false; - $scope.hasGravatar = r; + $timeout(function() { + $scope.isLoading = false; + $scope.hasGravatar = r; + }, 1); }; $scope.$watch('size', function(size) {