framework/ember/app/helpers/user-avatar.js
2015-02-26 12:47:50 +10:30

23 lines
705 B
JavaScript

import Ember from 'ember';
export default Ember.Handlebars.makeBoundHelper(function(user, options) {
var attributes = 'class="avatar '+(options.hash.class || '')+'"';
var content = '';
if (user) {
var username = user.get('username') || '?';
attributes += ' title="'+Ember.Handlebars.Utils.escapeExpression(username)+'"';
var avatarUrl = user.get('avatarUrl');
if (avatarUrl) {
return new Ember.Handlebars.SafeString('<img src="'+avatarUrl+'" '+attributes+'>');
}
content = username.charAt(0).toUpperCase();
attributes += ' style="background:'+user.get('color')+'"';
}
return new Ember.Handlebars.SafeString('<span '+attributes+'>'+content+'</span>');
});