sogo/UI/WebServerResources/js/Common/sgGravatarImage.directive.js

36 lines
982 B
JavaScript
Raw Normal View History

/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
(function() {
'use strict';
/**
* sgGravatarImage - A simple Gravatar directive (based on http://blog.lingohub.com/2014/08/better-ux-with-angularjs-directives/)
* @memberof SOGo.Common
* @example:
<sg-gravatar-image email="test@email.com" size="50"></sg-gravatar-image>
*/
2015-05-06 23:45:28 +02:00
sgGravatarImage.$inject = ['Gravatar'];
function sgGravatarImage(Gravatar) {
return {
restrict: 'AE',
replace: true,
required: 'email',
template: '<img ng-src="{{url}}"/>',
link: function(scope, element, attrs) {
2015-05-06 23:45:28 +02:00
var size = attrs.size;
element.attr('width', size);
element.attr('height', size);
attrs.$observe('email', function(value) {
if (!value) { return; }
2015-05-06 23:45:28 +02:00
scope.url = Gravatar(value, size);
});
}
};
}
angular
.module('SOGo.Common')
.directive('sgGravatarImage', sgGravatarImage);
})();