framework/js/lib/helpers/avatar.js

27 lines
642 B
JavaScript
Raw Normal View History

2015-04-25 20:58:39 +08:00
export default function avatar(user, args) {
args = args || {}
args.className = 'avatar '+(args.className || '')
var content = ''
var title = typeof args.title === 'undefined' || args.title
if (!title) { delete args.title }
if (user) {
var username = user.username() || '?'
if (title) { args.title = args.title || username }
var avatarUrl = user.avatarUrl()
if (avatarUrl) {
args.src = avatarUrl
return m('img', args)
}
content = username.charAt(0).toUpperCase()
args.style = {background: user.color()}
}
if (!args.title) { delete args.title }
return m('span', args, content)
}