<commit_before>class ActionButtonState extends Backbone.Model
  defaults:
    checked: false
    hovering: false
    loaded: false

  onClick: ->
    if @get('checked')
      @trigger 'click:checked'
    else
      @trigger 'click:unchecked'
    @set 'hovering', false

class window.ActionButtonView extends Backbone.Marionette.ItemView
  tagName: 'button'
  template: 'generic/action_button'

  constructor: (options={}) ->
    @model = new ActionButtonState

    @className += ' btn-action btn'
    @className += ' btn-mini' if options.mini

    super

    @bindInteractionEvents options.$listenToEl || @$el


  bindInteractionEvents: ($listenToEl)->
    @listenTo $listenToEl, 'click', @onClick
    @listenTo $listenToEl, 'mouseenter', @onMouseEnter
    @listenTo $listenToEl, 'mouseleave', @onMouseLeave

    @listenTo @model, 'change', @render
    @on 'render', @showCurrentState, @

  onClick: (e) ->
    e.preventDefault()
    e.stopPropagation()
    return unless @model.get('loaded')

    @model.onClick()

  onMouseEnter: -> @model.set 'hovering', true
  onMouseLeave: -> @model.set 'hovering', false

  showCurrentState: ->
    hovering = @model.get('hovering')
    checked = @model.get('checked')
    loaded = @model.get('loaded')

    @$el.toggleClass 'disabled', not loaded

    @$el.toggleClass 'btn-danger', hovering and checked and loaded
    @$el.toggleClass 'btn-primary', hovering and not checked and loaded
    @$el.toggleClass 'btn-action-checked', checked and loaded

    @trigger 'render_state', loaded, hovering, checked
<commit_msg>Fixed ActionButtonView to not use listenTo for jQuery events<commit_after>class ActionButtonState extends Backbone.Model
  defaults:
    checked: false
    hovering: false
    loaded: false

  onClick: ->
    if @get('checked')
      @trigger 'click:checked'
    else
      @trigger 'click:unchecked'
    @set 'hovering', false


class window.ActionButtonView extends Backbone.Marionette.ItemView
  tagName: 'button'
  template: 'generic/action_button'

  constructor: (options={}) ->
    @model = new ActionButtonState

    @className += ' btn-action btn'
    @className += ' btn-mini' if options.mini

    super

    @$listenToEl = options.$listenToEl || @$el
    @bindInteractionEvents()

  bindInteractionEvents: ->
    @$listenToEl.on 'click', @onClick
    @$listenToEl.on 'mouseenter', @onMouseEnter
    @$listenToEl.on 'mouseleave', @onMouseLeave

    @listenTo @model, 'change', @render
    @on 'render', @showCurrentState, @

  onClose: ->
    @listenToEl.off 'click', @onClick
    @listenToEl.off 'mouseenter', @onClick
    @listenToEl.off 'mouseleave', @onClick

  onClick: (e) =>
    e.preventDefault()
    e.stopPropagation()
    return unless @model.get('loaded')

    @model.onClick()

  onMouseEnter: => @model.set 'hovering', true
  onMouseLeave: => @model.set 'hovering', false

  showCurrentState: ->
    hovering = @model.get('hovering')
    checked = @model.get('checked')
    loaded = @model.get('loaded')

    @$el.toggleClass 'disabled', not loaded

    @$el.toggleClass 'btn-danger', hovering and checked and loaded
    @$el.toggleClass 'btn-primary', hovering and not checked and loaded
    @$el.toggleClass 'btn-action-checked', checked and loaded

    @trigger 'render_state', loaded, hovering, checked

{'fraction_non_alphanumeric': 0.13104287017330496, 'fraction_numerical': 0.0, 'mean_word_length': 3.713467048710602, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, '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': '4662849', 'n_tokens_mistral': 1043, 'n_tokens_neox': 1007, 'n_words': 253}