refactor avatars
This commit is contained in:
parent
fb8666b0e4
commit
2e51c25b1a
5 changed files with 49 additions and 43 deletions
|
@ -9,12 +9,7 @@ class App.WidgetAvatar extends App.Controller
|
||||||
App.User.unsubscribe(@subscribeId)
|
App.User.unsubscribe(@subscribeId)
|
||||||
|
|
||||||
render: (user) =>
|
render: (user) =>
|
||||||
@html App.view('avatar')(
|
@html user.avatar @size, @position, undefined, false, false, @type
|
||||||
user: user
|
|
||||||
size: @size
|
|
||||||
position: @position
|
|
||||||
type: @type
|
|
||||||
)
|
|
||||||
|
|
||||||
# start user popups
|
# start user popups
|
||||||
@userPopups(@position)
|
@userPopups(@position)
|
||||||
|
|
|
@ -46,40 +46,13 @@ class App.User extends App.Model
|
||||||
return '??'
|
return '??'
|
||||||
|
|
||||||
avatar: (size = 40, placement = '', cssClass = '', unique = false, avatar, type = undefined) ->
|
avatar: (size = 40, placement = '', cssClass = '', unique = false, avatar, type = undefined) ->
|
||||||
|
size = parseInt(size, 10)
|
||||||
|
|
||||||
|
cssClass += " " if cssClass
|
||||||
cssClass += "size-#{ size }"
|
cssClass += "size-#{ size }"
|
||||||
|
|
||||||
if placement
|
if placement
|
||||||
placement = "data-placement=\"#{placement}\""
|
placement = " data-placement='#{ placement }'"
|
||||||
|
|
||||||
# use system avatar for system actions
|
|
||||||
if @id is 1
|
|
||||||
return "<span class='avatar' style='background: white'>#{App.Utils.icon('logo')}</span>"
|
|
||||||
|
|
||||||
# use generated avatar
|
|
||||||
if !@image || @image is 'none' || unique
|
|
||||||
return @uniqueAvatar(size, placement, cssClass, avatar, type)
|
|
||||||
|
|
||||||
# use image as avatar
|
|
||||||
image = @imageUrl()
|
|
||||||
vip = @vip
|
|
||||||
if type is 'personal'
|
|
||||||
vip = false
|
|
||||||
else
|
|
||||||
cssClass += ' user-popover'
|
|
||||||
|
|
||||||
if vip
|
|
||||||
return "<span class=\"avatar #{cssClass}\" data-id=\"#{@id}\" style=\"background-image: url(#{image})\" #{placement}><svg class='icon icon-crown'><use xlink:href='#icon-crown'></svg></span>"
|
|
||||||
"<span class=\"avatar #{cssClass}\" data-id=\"#{@id}\" style=\"background-image: url(#{image})\" #{placement}></span>"
|
|
||||||
|
|
||||||
uniqueAvatar: (size, placement = '', cssClass = '', avatar, type) ->
|
|
||||||
width = 300
|
|
||||||
height = 226
|
|
||||||
size = parseInt(size, 10)
|
|
||||||
vip = @vip
|
|
||||||
|
|
||||||
rng = new Math.seedrandom(@id)
|
|
||||||
x = rng() * (width - size)
|
|
||||||
y = rng() * (height - size)
|
|
||||||
|
|
||||||
if !avatar
|
if !avatar
|
||||||
if type is 'personal'
|
if type is 'personal'
|
||||||
|
@ -92,9 +65,38 @@ class App.User extends App.Model
|
||||||
vip = false
|
vip = false
|
||||||
data = " data-avatar-id=\"#{avatar.id}\""
|
data = " data-avatar-id=\"#{avatar.id}\""
|
||||||
|
|
||||||
if vip
|
vip = @vip
|
||||||
return "<span class=\"avatar unique #{cssClass}\" #{data} style=\"background-position: -#{ x }px -#{ y }px;\" #{placement}><svg class='icon icon-crown'><use xlink:href='#icon-crown'></svg>#{ @initials() }</span>"
|
if type is 'personal'
|
||||||
"<span class=\"avatar unique #{cssClass}\" #{data} style=\"background-position: -#{ x }px -#{ y }px;\" #{placement}>#{ @initials() }</span>"
|
vip = false
|
||||||
|
else
|
||||||
|
cssClass += ' user-popover'
|
||||||
|
|
||||||
|
# use system avatar for system actions
|
||||||
|
if @id is 1
|
||||||
|
return App.view('avatar_system')()
|
||||||
|
else if !@image || @image is 'none' || unique
|
||||||
|
width = 300
|
||||||
|
height = 226
|
||||||
|
|
||||||
|
rng = new Math.seedrandom(@id)
|
||||||
|
x = rng() * (width - size)
|
||||||
|
y = rng() * (height - size)
|
||||||
|
|
||||||
|
return App.view('avatar_unique')
|
||||||
|
data: data
|
||||||
|
cssClass: cssClass
|
||||||
|
placement: placement
|
||||||
|
vip: vip
|
||||||
|
x: x
|
||||||
|
y: y
|
||||||
|
initials: @initials()
|
||||||
|
else
|
||||||
|
return App.view('avatar')
|
||||||
|
data: data
|
||||||
|
cssClass: cssClass
|
||||||
|
placement: placement
|
||||||
|
vip: vip
|
||||||
|
url: @imageUrl()
|
||||||
|
|
||||||
imageUrl: ->
|
imageUrl: ->
|
||||||
return if !@image
|
return if !@image
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
<%- @user.avatar(@size, @position, @class, false, false, @type) %>
|
<span class="avatar <%- @cssClass %>" style="background-image: url(<%- @url %>)"<%- @placement %><%- @data %>>
|
||||||
|
<%- @Icon('crown') if @vip %>
|
||||||
|
</span>
|
3
app/assets/javascripts/app/views/avatar_system.jst.eco
Normal file
3
app/assets/javascripts/app/views/avatar_system.jst.eco
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<span class="avatar <%- @cssClass %>" style="background: white">
|
||||||
|
<%- @Icon('logo') %>
|
||||||
|
</span>
|
4
app/assets/javascripts/app/views/avatar_unique.jst.eco
Normal file
4
app/assets/javascripts/app/views/avatar_unique.jst.eco
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<span class="avatar <%- @cssClass %> unique" style="background-position: -<%- @x %>px -<%- @y %>px;"<%- @placement %><%- @data %>>
|
||||||
|
<%- @Icon('crown') if @vip %>
|
||||||
|
<%= @initials %>
|
||||||
|
</span>
|
Loading…
Reference in a new issue