<commit_before>class AvatarView extends LinkView

  constructor:(options = {},data)->

    options.cssClass or= ""
    options.size     or=
      width            : 50
      height           : 50
    options.detailed  ?= no

    # this needs to be pre-super
    if options.detailed
      @detailedAvatar   =
        constructorName : AvatarTooltipView
        options         :
          delegate      : @
          origin        : options.origin
        data            : data

      options.tooltip or= {}
      options.tooltip.view         or= if options.detailed then @detailedAvatar else null
      options.tooltip.viewCssClass or= 'avatar-tooltip'
      options.tooltip.animate      or= yes
      options.tooltip.placement    or= 'top'
      options.tooltip.direction    or= 'right'

    options.cssClass = "avatarview #{options.cssClass}"

    super options,data

    if @detailedAvatar?
      @on 'TooltipReady', =>
        @utils.defer =>
          data = @getData()
          @tooltip.getView().updateData data if data?.profile.nickname

    @bgImg = null

  # click:(event)->
  #   event.stopPropagation()
  #   event.preventDefault()
  #   @getTooltip().hide()
  #   @utils.defer => @emit 'LinkClicked'
  #   return no

  render:->
    account = @getData()
    return unless account
    {profile} = account
    options = @getOptions()
    fallbackUri = "#{KD.apiUri}/images/defaultavatar/default.avatar.#{options.size.width}.png"

    # this is a temp fix to avoid avatar flashing on every account change - Sinan 08/2012
    bgImg = "url(//gravatar.com/avatar/#{profile.hash}?size=#{options.size.width}&d=#{encodeURIComponent fallbackUri})"

    if @bgImg isnt bgImg
      @$().css "background-image", bgImg
      @bgImg = bgImg

    flags = account.globalFlags?.join(" ") ? ""
    @$('cite').addClass flags

  viewAppended:->
    super
    @render() if @getData()

  pistachio:-> '<cite></cite>'


class AvatarTooltipView extends KDView
  constructor:(options={}, data)->

    super options, data

    origin = options.origin

    @profileName = new KDCustomHTMLView
      tagName : 'a'
      cssClass : 'profile-name'
      # click:(event)=>
      #   KD.getSingleton('router').handleRoute "/#{@getData().profile.nickname}", state:@getData()
      attributes:
        href : "/#{@getData().profile.nickname}"
        target : '_blank'
      pistachio : \<commit_msg>Fix avatar view for guests<commit_after>class AvatarView extends LinkView

  constructor:(options = {},data)->

    options.cssClass or= ""
    options.size     or=
      width            : 50
      height           : 50
    options.detailed  ?= no

    # this needs to be pre-super
    if options.detailed
      @detailedAvatar   =
        constructorName : AvatarTooltipView
        options         :
          delegate      : @
          origin        : options.origin
        data            : data

      options.tooltip or= {}
      options.tooltip.view         or= if options.detailed then @detailedAvatar else null
      options.tooltip.viewCssClass or= 'avatar-tooltip'
      options.tooltip.animate      or= yes
      options.tooltip.placement    or= 'top'
      options.tooltip.direction    or= 'right'

    options.cssClass = "avatarview #{options.cssClass}"

    super options,data

    if @detailedAvatar?
      @on 'TooltipReady', =>
        @utils.defer =>
          data = @getData()
          @tooltip.getView().updateData data if data?.profile.nickname

    @bgImg = null
    @fallbackUri = "#{KD.apiUri}/images/defaultavatar/default.avatar.#{options.size.width}.png"

  setAvatar:(uri)->
    if @bgImg isnt uri
      @$().css "background-image", uri
      @bgImg = uri

  render:->
    account = @getData()
    return unless account

    {profile, type} = account
    return @setAvatar "url(#{@fallbackUri})"  if type is 'unregistered'

    {width} = @getOptions().size
    @setAvatar "url(//gravatar.com/avatar/#{profile.hash}?size=#{width}&d=#{encodeURIComponent @fallbackUri})"

    flags = account.globalFlags?.join(" ") ? ""
    @$('cite').addClass flags

  viewAppended:->
    super
    @render() if @getData()

  pistachio:-> '<cite></cite>'


class AvatarTooltipView extends KDView
  constructor:(options={}, data)->

    super options, data

    origin = options.origin

    @profileName = new KDCustomHTMLView
      tagName : 'a'
      cssClass : 'profile-name'
      attributes:
        href : "/#{@getData().profile.nickname}"
        target : '_blank'
      pistachio : \
{'fraction_non_alphanumeric': 0.1271186440677966, 'fraction_numerical': 0.0031222123104371097, 'mean_word_length': 2.3645911477869466, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4934554', 'n_tokens_mistral': 1375, 'n_tokens_neox': 1335, 'n_words': 303}