mirror of
https://github.com/flarum/framework.git
synced 2024-11-27 11:03:37 +08:00
27 lines
642 B
JavaScript
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)
|
|
}
|