<commit_before>class Button
  constructor: (dom_events={}) ->
    @frame = new FactlinkJailRoot.ControlIframe()
    @frame.setContent($.parseHTML(@content.trim())[0])
    @$el =  $(@frame.frameBody.firstChild)
    for event, callback of dom_events
      @$el.on event, callback

  startLoading: => @$el.addClass "fl-button-loading"
  stopLoading:  => @$el.removeClass  "fl-button-loading"

  setCoordinates: (top, left) =>
    @_top = top
    @_left = left

  show: =>
    @stopLoading()
    @frame.fadeIn()

    left = @_left - @frame.$el.outerWidth(true)/2
    top = @_top - @frame.$el.outerHeight(true)

    @frame.$el.css
      left: left + "px"
      top: top + "px"

  hide: => @frame.fadeOut()

  destroy: => @frame.destroy()

class FactlinkJailRoot.ShowButton extends Button
  content: """
    <div class="fl-button">
      <span class="fl-button-default-content">Show Annotation</span>
      <span class="fl-button-loading-content">Loading...</span>
    </div>
  """


class FactlinkJailRoot.CreateButton extends Button
  content: """
    <div class="fl-button">
      <span class="fl-button-default-content">Add Annotation</span>
      <span class="fl-button-loading-content">Loading...</span>
    </div>
  """

  placeNearSelection: (mouseX=null) ->
    selectionBox = window.document.getSelection().getRangeAt(0).getBoundingClientRect()
    top = selectionBox.top + $(window).scrollTop() - 2
    left = mouseX ? (selectionBox.left + selectionBox.width/2)

    @setCoordinates top, left<commit_msg>Also fixed horizontal offset when using extension button<commit_after>class Button
  constructor: (dom_events={}) ->
    @frame = new FactlinkJailRoot.ControlIframe()
    @frame.setContent($.parseHTML(@content.trim())[0])
    @$el =  $(@frame.frameBody.firstChild)
    for event, callback of dom_events
      @$el.on event, callback

  startLoading: => @$el.addClass "fl-button-loading"
  stopLoading:  => @$el.removeClass  "fl-button-loading"

  setCoordinates: (top, left) =>
    @_top = top
    @_left = left

  show: =>
    @stopLoading()
    @frame.fadeIn()

    left = @_left - @frame.$el.outerWidth(true)/2
    top = @_top - @frame.$el.outerHeight(true)

    @frame.$el.css
      left: left + "px"
      top: top + "px"

  hide: => @frame.fadeOut()

  destroy: => @frame.destroy()

class FactlinkJailRoot.ShowButton extends Button
  content: """
    <div class="fl-button">
      <span class="fl-button-default-content">Show Annotation</span>
      <span class="fl-button-loading-content">Loading...</span>
    </div>
  """


class FactlinkJailRoot.CreateButton extends Button
  content: """
    <div class="fl-button">
      <span class="fl-button-default-content">Add Annotation</span>
      <span class="fl-button-loading-content">Loading...</span>
    </div>
  """

  placeNearSelection: (mouseX=null) ->
    selectionBox = window.document.getSelection().getRangeAt(0).getBoundingClientRect()
    top = selectionBox.top + $(window).scrollTop() - 2
    left = mouseX ? ($(window).scrollLeft() + selectionBox.left + selectionBox.width/2)

    @setCoordinates top, left
{'fraction_non_alphanumeric': 0.1642903434867142, 'fraction_numerical': 0.0032404406999351912, 'mean_word_length': 3.441726618705036, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 43, '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': '2975554', 'n_tokens_mistral': 1032, 'n_tokens_neox': 1001, 'n_words': 191}