<commit_before>(function() {
  "use strict";
  App.LegislationAnnotatable = {
    makeEditableAndHighlight: function(colour) {
      var range, sel;
      sel = window.getSelection();
      if (sel.rangeCount && sel.getRangeAt) {
        range = sel.getRangeAt(0);
      }
      document.designMode = "on";
      if (range) {
        sel.removeAllRanges();
        sel.addRange(range);
      }
      if (!document.execCommand("HiliteColor", false, colour)) {
        document.execCommand("BackColor", false, colour);
      }
      document.designMode = "off";
    },
    highlight: function(colour) {
      try {
        if (!document.execCommand("BackColor", false, colour)) {
          App.LegislationAnnotatable.makeEditableAndHighlight(colour);
        }
      } catch (error) {
        App.LegislationAnnotatable.makeEditableAndHighlight(colour);
      }
    },
    remove_highlight: function() {
      $("[data-legislation-draft-version-id] span[style]").replaceWith(function() {
        return $(this).contents();
      });
    },
    renderAnnotationComments: function(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: function(event) {
      var annotation_id, annotation_url, parents, parents_ids, target;
      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(function(_, elem) {
        return $(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(function(i, pid) {
        $.event.trigger({
          type: "renderLegislationAnnotation",
          annotation_id: pid,
          annotation_url: target.closest(".legislation-annotatable").data("legislation-annotatable-base-url")
        });
      });
    },
    isMobile: function() {
      return window.innerWidth <= 652;
    },
    viewerExtension: function(viewer) {
      return viewer._onHighlightMouseover = function() {};
    },
    customShow: function(position) {
      var annotation_url;
      $(this.element).html("");
      // Clean comments section and open it
      $("#comments-box").html("");
      App.LegislationAllegations.show_comments();
      $("#comments-box").show();
      annotation_url = $("[data-legislation-annotatable-base-url]").data("legislation-annotatable-base-url");
      $.ajax({
        method: "GET",
        url: annotation_url + "/annotations/new",
        dataType: "script"
      }).done((function() {
        $("#new_legislation_annotation #legislation_annotation_quote").val(this.annotation.quote);
        $("#new_legislation_annotation #legislation_annotation_ranges").val(JSON.stringify(this.annotation.ranges));
        $("#comments-box").css({
          top: position.top - $(".calc-comments").offset().top
        });
        if ($("[data-legislation-open-phase]").data("legislation-open-phase") !== false) {
          App.LegislationAnnotatable.highlight("#7fff9a");
          $("#comments-box textarea").focus();
          $("#new_legislation_annotation").on("ajax:complete", function(e, data) {
            if (data.status === 200) {
              App.LegislationAnnotatable.remove_highlight();
              App.LegislationAnnotatable.app.annotations.runHook("annotationCreated", [data.responseJSON]);
              $("#comments-box").html("").hide();
              $.ajax({
                method: "GET",
                url: annotation_url + "/annotations/" + data.responseJSON.id + "/comments",
                dataType: "script"
              });
            } else {<commit_msg>Extract duplicated code to method<commit_after>(function() {
  "use strict";
  App.LegislationAnnotatable = {
    makeEditableAndHighlight: function(colour) {
      var range, sel;
      sel = window.getSelection();
      if (sel.rangeCount && sel.getRangeAt) {
        range = sel.getRangeAt(0);
      }
      document.designMode = "on";
      if (range) {
        sel.removeAllRanges();
        sel.addRange(range);
      }
      if (!document.execCommand("HiliteColor", false, colour)) {
        document.execCommand("BackColor", false, colour);
      }
      document.designMode = "off";
    },
    highlight: function(colour) {
      try {
        if (!document.execCommand("BackColor", false, colour)) {
          App.LegislationAnnotatable.makeEditableAndHighlight(colour);
        }
      } catch (error) {
        App.LegislationAnnotatable.makeEditableAndHighlight(colour);
      }
    },
    remove_highlight: function() {
      $("[data-legislation-draft-version-id] span[style]").replaceWith(function() {
        return $(this).contents();
      });
    },
    loadAnnotationComments: function(annotation_url, annotation_id) {
      $.ajax({
        method: "GET",
        url: annotation_url + "/annotations/" + annotation_id + "/comments",
        dataType: "script"
      });
    },
    renderAnnotationComments: function(event) {
      if (event.offset) {
        $("#comments-box").css({
          top: event.offset - $(".calc-comments").offset().top
        });
      }
      if (App.LegislationAnnotatable.isMobile()) {
        return;
      }
      App.LegislationAnnotatable.loadAnnotationComments(event.annotation_url, event.annotation_id);
    },
    onClick: function(event) {
      var annotation_id, annotation_url, parents, parents_ids, target;
      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(function(_, elem) {
        return $(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(function(i, pid) {
        $.event.trigger({
          type: "renderLegislationAnnotation",
          annotation_id: pid,
          annotation_url: target.closest(".legislation-annotatable").data("legislation-annotatable-base-url")
        });
      });
    },
    isMobile: function() {
      return window.innerWidth <= 652;
    },
    viewerExtension: function(viewer) {
      return viewer._onHighlightMouseover = function() {};
    },
    customShow: function(position) {
      var annotation_url;
      $(this.element).html("");
      // Clean comments section and open it
      $("#comments-box").html("");
      App.LegislationAllegations.show_comments();
      $("#comments-box").show();
      annotation_url = $("[data-legislation-annotatable-base-url]").data("legislation-annotatable-base-url");
      $.ajax({
        method: "GET",
        url: annotation_url + "/annotations/new",
        dataType: "script"
      }).done((function() {
        $("#new_legislation_annotation #legislation_annotation_quote").val(this.annotation.quote);
        $("#new_legislation_annotation #legislation_annotation_ranges").val(JSON.stringify(this.annotation.ranges));
        $("#comments-box").css({
          top: position.top - $(".calc-comments").offset().top
        });
        if ($("[data-legislation-open-phase]").data("legislation-open-phase") !== false) {
          App.LegislationAnnotatable.highlight("#7fff9a");
          $("#comments-box textarea").focus();
          $("#new_legislation_annotation").on("ajax:complete", function(e, data) {
            if (data.status === 200) {
              App.LegislationAnnotatable.remove_highlight();
              App.LegislationAnnotatable.app.annotations.runHook("annotationCreated", [data.responseJSON]);
              $("#comments-box").html("").hide();
              App.LegislationAnnotatable.loadAnnotationComments(annotation_url, data.responseJSON.id);
            } else {
{'fraction_non_alphanumeric': 0.1622265989426765, 'fraction_numerical': 0.0018658650357624132, 'mean_word_length': 2.765807962529274, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6607075', 'n_tokens_mistral': 2780, 'n_tokens_neox': 2751, 'n_words': 389}