<commit_before>var scalexProd = /scalex\.org/.test(document.domain);

$(function () {

  var $form = $("form.search-form");
  var $input = $form.find("input");
  var $results = $(".results");
  var $resultTpl = $("#result-template");
  var $greetings = $(".greetings");
  var xhr;

  if (!scalexProd) $form.attr("data-url", "http://api.scalex.local");

  // put request query in the search input
  if (query = getParameterByName("q")) $input.val(query);

  // instant search
  $input.bind("keyup", function () {
    if (xhr) xhr.abort();
    if (query = inputVal()) search(query);
    else toggle("greetings");
  });

  // first search: jump to url hash if possible
  if (query = inputVal()) {
    search(query, {
      callback: function () {
        if (window.location.hash && ($fun = $(window.location.hash)).length) {
          activate($fun);
          $('html,body').animate({
            "scrollTop": $fun.offset().top
          }, 300);
        }
      }
    });
  } else toggle("greetings");

  // expand search results
  $("div.results").on("click", "a.doc-url", function(e) {
    e.stopPropagation();
    return true;
  });
  $("div.results").on("click", ".result", function() {
    activate($(this));
  });

  // transform code examples to search links
  $greetings.find('code').each(function () {
    $(this).wrap('<a href="?q=' + $(this).text() + '">');
  });

  function inputVal() {
    return $.trim($input.val());
  }

  // toggle between greetings and search results
  function toggle(s) {
    $(window).unbind("smartscroll");
    $greetings.toggle(s != "search");
    $results.toggle(s == "search");
  }

  function activate($fun) {
    $results.find(".active").not($fun).removeClass("active");
    $fun.toggleClass("active");
  }

  function search(query, o) {
    var options = $.extend({<commit_msg>Encode code example urls<commit_after>var scalexProd = /scalex\.org/.test(document.domain);

$(function () {

  var $form = $("form.search-form");
  var $input = $form.find("input");
  var $results = $(".results");
  var $resultTpl = $("#result-template");
  var $greetings = $(".greetings");
  var xhr;

  if (!scalexProd) $form.attr("data-url", "http://api.scalex.local");

  // put request query in the search input
  if (query = getParameterByName("q")) $input.val(query);

  // instant search
  $input.bind("keyup", function () {
    if (xhr) xhr.abort();
    if (query = inputVal()) search(query);
    else toggle("greetings");
  });

  // first search: jump to url hash if possible
  if (query = inputVal()) {
    search(query, {
      callback: function () {
        if (window.location.hash && ($fun = $(window.location.hash)).length) {
          activate($fun);
          $('html,body').animate({
            "scrollTop": $fun.offset().top
          }, 300);
        }
      }
    });
  } else toggle("greetings");

  // expand search results
  $("div.results").on("click", "a.doc-url", function(e) {
    e.stopPropagation();
    return true;
  });
  $("div.results").on("click", ".result", function() {
    activate($(this));
  });

  // transform code examples to search links
  $greetings.find('code').each(function () {
    $(this).wrap('<a href="?q=' + encodeURIComponent($(this).text()) + '">');
  });

  function inputVal() {
    return $.trim($input.val());
  }

  // toggle between greetings and search results
  function toggle(s) {
    $(window).unbind("smartscroll");
    $greetings.toggle(s != "search");
    $results.toggle(s == "search");
  }

  function activate($fun) {
    $results.find(".active").not($fun).removeClass("active");
    $fun.toggleClass("active");
  }

  function search(query, o) {
    var options = $.extend({
{'fraction_non_alphanumeric': 0.2088659233070438, 'fraction_numerical': 0.0016317650258362796, 'mean_word_length': 3.0957683741648108, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, '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': '553012', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1186, 'n_words': 250}