framework/js/lib/helpers/avatar.js
2015-04-25 22:28:39 +09:30

27 lines
642 B
JavaScript

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)
}