<commit_before>_t = (key) -> new Gettext().gettext(key)

App.LegislationAnnotatable =

  makeEditableAndHighlight: (colour) ->
    sel = window.getSelection()
    if sel.rangeCount and sel.getRangeAt
      range = sel.getRangeAt(0)
    document.designMode = 'on'
    if range
      sel.removeAllRanges()
      sel.addRange range
    # Use HiliteColor since some browsers apply BackColor to the whole block
    if !document.execCommand('HiliteColor', false, colour)
      document.execCommand 'BackColor', false, colour
    document.designMode = 'off'
    return

  highlight: (colour) ->
    if window.getSelection
      # IE9 and non-IE
      try
        if !document.execCommand('BackColor', false, colour)
          App.LegislationAnnotatable.makeEditableAndHighlight colour
      catch ex
        App.LegislationAnnotatable.makeEditableAndHighlight colour
    else if document.selection and document.selection.createRange
      # IE <= 8 case
      range = document.selection.createRange()
      range.execCommand 'BackColor', false, colour
    return

  remove_highlight: ->
    $('[data-legislation-draft-version-id] span[style]').replaceWith(->
      return $(this).contents()
    )
    return

  renderAnnotationComments: (event) ->
    if event.offset
      $("#comments-box").css({top: event.offset - $('.calc-comments').offset().top})

    if App.LegislationAnnotatable.isMobile()
      return

    $.ajax
      method: "GET"
      url: event.annotation_url + "/annotations/" + event.annotation_id + "/comments"
      dataType: 'script'

  onClick: (event) ->
    event.preventDefault()
    event.stopPropagation()

    if App.LegislationAnnotatable.isMobile()
      annotation_url = $(event.target).closest(".legislation-annotatable").data("legislation-annotatable-base-url")
      window.location.href = annotation_url + "/annotations/" + $(this).data('annotation-id')
      return

    $('[data-annotation-id]').removeClass('current-annotation')

    target = $(this)

    parents = target.parents('.annotator-hl')
    parents_ids = parents.map (_, elem) ->
      $(elem).data("annotation-id")

    annotation_id = target.data('annotation-id')
    $('[data-annotation-id="' + annotation_id + '"]').addClass('current-annotation')

    $('#comments-box').html('')
    App.LegislationAllegations.show_comments()
    $("#comments-box").show()

    $.event.trigger
      type: "renderLegislationAnnotation"
      annotation_id: target.data("annotation-id")
      annotation_url: target.closest(".legislation-annotatable").data("legislation-annotatable-base-url")
      offset: target.offset()["top"]

    parents_ids.each (i, pid) ->
      $.event.trigger
        type: "renderLegislationAnnotation"
        annotation_id: pid
        annotation_url: target.closest(".legislation-annotatable").data("legislation-annotatable-base-url")

  isMobile: () ->
    return window.innerWidth <= 652

  viewerExtension: (viewer) ->
    viewer._onHighlightMouseover = (event) ->
      return

  customShow: (position) -><commit_msg>Remove unnecesary empty parameter list on coffeescript file<commit_after>_t = (key) -> new Gettext().gettext(key)

App.LegislationAnnotatable =

  makeEditableAndHighlight: (colour) ->
    sel = window.getSelection()
    if sel.rangeCount and sel.getRangeAt
      range = sel.getRangeAt(0)
    document.designMode = 'on'
    if range
      sel.removeAllRanges()
      sel.addRange range
    # Use HiliteColor since some browsers apply BackColor to the whole block
    if !document.execCommand('HiliteColor', false, colour)
      document.execCommand 'BackColor', false, colour
    document.designMode = 'off'
    return

  highlight: (colour) ->
    if window.getSelection
      # IE9 and non-IE
      try
        if !document.execCommand('BackColor', false, colour)
          App.LegislationAnnotatable.makeEditableAndHighlight colour
      catch ex
        App.LegislationAnnotatable.makeEditableAndHighlight colour
    else if document.selection and document.selection.createRange
      # IE <= 8 case
      range = document.selection.createRange()
      range.execCommand 'BackColor', false, colour
    return

  remove_highlight: ->
    $('[data-legislation-draft-version-id] span[style]').replaceWith(->
      return $(this).contents()
    )
    return

  renderAnnotationComments: (event) ->
    if event.offset
      $("#comments-box").css({top: event.offset - $('.calc-comments').offset().top})

    if App.LegislationAnnotatable.isMobile()
      return

    $.ajax
      method: "GET"
      url: event.annotation_url + "/annotations/" + event.annotation_id + "/comments"
      dataType: 'script'

  onClick: (event) ->
    event.preventDefault()
    event.stopPropagation()

    if App.LegislationAnnotatable.isMobile()
      annotation_url = $(event.target).closest(".legislation-annotatable").data("legislation-annotatable-base-url")
      window.location.href = annotation_url + "/annotations/" + $(this).data('annotation-id')
      return

    $('[data-annotation-id]').removeClass('current-annotation')

    target = $(this)

    parents = target.parents('.annotator-hl')
    parents_ids = parents.map (_, elem) ->
      $(elem).data("annotation-id")

    annotation_id = target.data('annotation-id')
    $('[data-annotation-id="' + annotation_id + '"]').addClass('current-annotation')

    $('#comments-box').html('')
    App.LegislationAllegations.show_comments()
    $("#comments-box").show()

    $.event.trigger
      type: "renderLegislationAnnotation"
      annotation_id: target.data("annotation-id")
      annotation_url: target.closest(".legislation-annotatable").data("legislation-annotatable-base-url")
      offset: target.offset()["top"]

    parents_ids.each (i, pid) ->
      $.event.trigger
        type: "renderLegislationAnnotation"
        annotation_id: pid
        annotation_url: target.closest(".legislation-annotatable").data("legislation-annotatable-base-url")

  isMobile: ->
    return window.innerWidth <= 652

  viewerExtension: (viewer) ->
    viewer._onHighlightMouseover = (event) ->
      return

  customShow: (position) ->
{'fraction_non_alphanumeric': 0.13632639685400622, 'fraction_numerical': 0.0019662461084712438, 'mean_word_length': 3.3260099220411057, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, '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': '4437877', 'n_tokens_mistral': 1848, 'n_tokens_neox': 1782, 'n_words': 333}