<commit_before>class window.EvidenceVoteView extends Backbone.Marionette.ItemView
  _.extend @prototype, Backbone.Factlink.PopoverMixin

  className: 'evidence-impact-vote'
  template: 'evidence/evidence_vote'

  events:
    "click .js-up":   "_on_up_vote"
    "click .js-down": "_on_down_vote"

  initialize: ->
    @listenTo @model, "change", @render

  onRender: ->
    @$('a.js-up').addClass('active') if @model.get('current_user_opinion') == 'believes'
    @$('a.js-down').addClass('active')  if @model.get('current_user_opinion') == 'disbelieves'

  _on_up_vote: ->
    mp_track "Factlink: Upvote evidence click"
    if @model instanceof FactRelation && Factlink.Global.can_haz['vote_up_down_popup']
      @_open_vote_popup '.js-up', FactRelationVoteUpView
    else
      if @model.isBelieving()
        @model.removeOpinion()
      else
        @model.believe()

  _on_down_vote: ->
    mp_track "Factlink: Downvote evidence click"
    if @model instanceof FactRelation && Factlink.Global.can_haz['vote_up_down_popup']
      @_open_vote_popup '.js-down',  FactRelationVoteDownView
    else
      if @model.isDisBelieving()
        @model.removeOpinion()
      else
        @model.disbelieve()

  _open_vote_popup: (selector, view_klass) ->
    return if @popoverOpened selector

    @popoverResetAll()
    @popoverAdd selector,
      side: @_side()
      align: 'top'
      fadeTime: 40
      contentView: new view_klass model: @model

  _side: ->
    if @model.get('type') == 'believes'
      'left'
    else
      'right'
<commit_msg>Dont rerender entire EvidenceVoteView when opinion changes, this breaks the popover<commit_after>class window.EvidenceVoteView extends Backbone.Marionette.ItemView
  _.extend @prototype, Backbone.Factlink.PopoverMixin

  className: 'evidence-impact-vote'
  template: 'evidence/evidence_vote'

  events:
    "click .js-up":   "_on_up_vote"
    "click .js-down": "_on_down_vote"

  initialize: ->
    @listenTo @model, "change", @_updateButtons

  onRender: ->
    @_updateButtons()

  _updateButtons: ->
    @$('a.js-up').toggleClass 'active', @model.get('current_user_opinion') == 'believes'
    @$('a.js-down').toggleClass 'active', @model.get('current_user_opinion') == 'disbelieves'

  _on_up_vote: ->
    mp_track "Factlink: Upvote evidence click"
    if @model instanceof FactRelation && Factlink.Global.can_haz['vote_up_down_popup']
      @_open_vote_popup '.js-up', FactRelationVoteUpView
    else
      if @model.isBelieving()
        @model.removeOpinion()
      else
        @model.believe()

  _on_down_vote: ->
    mp_track "Factlink: Downvote evidence click"
    if @model instanceof FactRelation && Factlink.Global.can_haz['vote_up_down_popup']
      @_open_vote_popup '.js-down',  FactRelationVoteDownView
    else
      if @model.isDisBelieving()
        @model.removeOpinion()
      else
        @model.disbelieve()

  _open_vote_popup: (selector, view_klass) ->
    return if @popoverOpened selector

    @popoverResetAll()
    @popoverAdd selector,
      side: @_side()
      align: 'top'
      fadeTime: 40
      contentView: new view_klass model: @model

  _side: ->
    if @model.get('type') == 'believes'
      'left'
    else
      'right'

{'fraction_non_alphanumeric': 0.12628624883068287, 'fraction_numerical': 0.0012472715933894605, 'mean_word_length': 3.400548696844993, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 16, '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': '2649560', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1075, 'n_words': 212}