This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/static/js/directives/ng-image-watch.js

24 lines
640 B
JavaScript
Raw Normal View History

2019-11-12 16:09:47 +00:00
/**
* Adds a ng-image-watch attribute, which is a callback invoked when the image is loaded or fails.
*/
angular.module('quay').directive('ngImageWatch', function ($parse) {
return {
restrict: 'A',
compile: function($element, attr) {
var fn = $parse(attr['ngImageWatch']);
return function(scope, element) {
element.bind('error', function() {
scope.$apply(function() {
fn(scope, {result: false});
})
});
element.bind('load', function() {
scope.$apply(function() {
fn(scope, {result: true});
})
});
}
}
};
});