<commit_before>$(window).on('load', function() {
  var $color = $("#color");
  var $color_text = $("#color_text");
  var $background_color = $("#background_color");
  var $background_color_text = $("#background_color_text");
  var $search = $("#search");
  var $right = $('#right');
  var $size = $("#size");
  var $download = $("#download");
  var $stackedLabel = $("#stacked_label");
  var $stackedSize = $("#stacked_size");
  var $downloadIframe = $("#download_iframe");
  var $fileFormatText = $("#file_format_text");

  var createFaviconUrl = "https://fonticon-207412.appspot.com/";
  var loading = false;
  var symbol = "\uf004";
  var symbolStyle = "s";
  var stackedSelected = false;
  var stackedSymbol = "\uf004";
  var stackedSymbolStyle = "s";
  var canvas = document.getElementById('canvas');
  var sideLength = 1024;
  canvas.width = sideLength;
  canvas.height = sideLength;
  var ctx = canvas.getContext('2d');
  ctx.textAlign = "center";
  ctx.textBaseline = "middle";
  initialize();

  function initialize() {
    $size.on("input", draw);
    $stackedSize.on("input", draw);
    $color_text.on("input", updateColor.bind(updateColor, $color, $color_text,
                                             false, true));
    $background_color_text.on(
        "input", updateColor.bind(updateColor, $background_color,
                                  $background_color_text, false, true));
    $color.spectrum({
      color : "#ff3860",
      showButtons : false,
      showAlpha : true,
      move : updateColor.bind(updateColor, $color, $color_text, true, true)
    });

    $background_color.spectrum({
      color : "rgba(255,255,255,0)",
      showButtons : false,
      showAlpha : true,
      move : updateColor.bind(updateColor, $background_color,
                              $background_color_text, true, true)
    });
    updateColor($color, $color_text, false, false);
    updateColor($background_color, $background_color_text, false, false);

    initSearch($search, $right);

    function loadingFinished() {
      loading = false;
      $download.removeClass("loading");
    }

    function iconCreationError(errorMessage) { console.error(errorMessage); }

    $download.on("click", function() {
      if (!loading) {
        loading = true;
        $download.addClass("loading");
        if ($fileFormatText.text() == ".ico") {
          var iconData = canvas.toDataURL().split(',')[1];
          $.ajax({
            type : "POST",
            url : createFaviconUrl,
            data : iconData,
            success : function(response) {
              if (response.status == "error") {
                iconCreationError(response.error_message);
              } else {
                $downloadIframe.attr('src', response.url);
              }
            },
            error : function(jqXHR, textStatus,
                             errorMessage) { iconCreationError(errorMessage); },
            complete : loadingFinished
          })
        } else {
          canvas.toBlob(function(blob) {
            saveAs(blob, "favicon.png");
            loadingFinished();
          });
        }
      }
    });

    $("#stacked").click(function() {
      stackedSelected = this.checked;
      this.checked ? $stackedSize.show() : $stackedSize.hide();
      draw();
    });

    $.each(icons, function(index, icon) {
      var $iconOuter = $("<div>").addClass("icon_outer").data("id", icon.id);

      var iconStyle;
      switch (icon.style) {
      case 'solid':
        iconStyle = 's';
        break;
      case 'regular':
        iconStyle = 'r';
        break;
      default:
        console.error('Unkown icon style.');
      }
      var styleClass = "fa" + iconStyle + " fa-" + icon.id;
      var $icon = $("<div>")
                      .addClass("icon hover")
                      .data('style', iconStyle)
                      .data('unicode', icon.unicode)
                      .append($('<i>').addClass(styleClass));
      $icon.append($("<div>").addClass("icon_text underline").text(icon.id));
      $iconOuter.append($icon);
      $right.append($iconOuter);
    });

    $(".icon").on("click touchstart", function() {
      var selectedSymbol = $(this).data('unicode');
      var selectedSymbolStyle = $(this).data('style');
      if (stackedSelected) {
        stackedSymbol = selectedSymbol;
        stackedSymbolStyle = selectedSymbolStyle;
      } else {
        symbol = selectedSymbol;
        symbolStyle = selectedSymbolStyle;
      }
      draw();
    });

    $("#file_format").on("click", function() {
      new_format = ".ico";
      if ($fileFormatText.text() == ".ico") {
        new_format = ".png";
      }
      $fileFormatText.text(new_format);
    });

    setTimeout(draw, 1000);
  }

  function initSearch($search, $right) {
    var options = {
      id : "id",
      shouldSort : true,
      threshold : 0.3,
      location : 0,
      distance : 100,
      maxPatternLength : 32,
      minMatchCharLength : 1,
      keys : [ "id", "name", "search" ]
    };
    var fuse = new Fuse(icons, options);
    $search.on("input", function() {
      var query = $search.get(0).value;
      var result = fuse.search(query);
      $right.children().hide();
      $right.children()
          .filter(function(index, element) {
            return query == "" || result.indexOf($(element).data("id")) != -1;
          })
          .show();
      if (result.length == 0 && query != "") {
        tinysort($right.children());
      } else if (result.length > 0) {
        tinysort($right.children(), {<commit_msg>Fix search to include search_terms, closes #12<commit_after>$(window).on('load', function() {
  var $color = $("#color");
  var $color_text = $("#color_text");
  var $background_color = $("#background_color");
  var $background_color_text = $("#background_color_text");
  var $search = $("#search");
  var $right = $('#right');
  var $size = $("#size");
  var $download = $("#download");
  var $stackedLabel = $("#stacked_label");
  var $stackedSize = $("#stacked_size");
  var $downloadIframe = $("#download_iframe");
  var $fileFormatText = $("#file_format_text");

  var createFaviconUrl = "https://fonticon-207412.appspot.com/";
  var loading = false;
  var symbol = "\uf004";
  var symbolStyle = "s";
  var stackedSelected = false;
  var stackedSymbol = "\uf004";
  var stackedSymbolStyle = "s";
  var canvas = document.getElementById('canvas');
  var sideLength = 1024;
  canvas.width = sideLength;
  canvas.height = sideLength;
  var ctx = canvas.getContext('2d');
  ctx.textAlign = "center";
  ctx.textBaseline = "middle";
  initialize();

  function initialize() {
    $size.on("input", draw);
    $stackedSize.on("input", draw);
    $color_text.on("input", updateColor.bind(updateColor, $color, $color_text,
                                             false, true));
    $background_color_text.on(
        "input", updateColor.bind(updateColor, $background_color,
                                  $background_color_text, false, true));
    $color.spectrum({
      color : "#ff3860",
      showButtons : false,
      showAlpha : true,
      move : updateColor.bind(updateColor, $color, $color_text, true, true)
    });

    $background_color.spectrum({
      color : "rgba(255,255,255,0)",
      showButtons : false,
      showAlpha : true,
      move : updateColor.bind(updateColor, $background_color,
                              $background_color_text, true, true)
    });
    updateColor($color, $color_text, false, false);
    updateColor($background_color, $background_color_text, false, false);

    initSearch($search, $right);

    function loadingFinished() {
      loading = false;
      $download.removeClass("loading");
    }

    function iconCreationError(errorMessage) { console.error(errorMessage); }

    $download.on("click", function() {
      if (!loading) {
        loading = true;
        $download.addClass("loading");
        if ($fileFormatText.text() == ".ico") {
          var iconData = canvas.toDataURL().split(',')[1];
          $.ajax({
            type : "POST",
            url : createFaviconUrl,
            data : iconData,
            success : function(response) {
              if (response.status == "error") {
                iconCreationError(response.error_message);
              } else {
                $downloadIframe.attr('src', response.url);
              }
            },
            error : function(jqXHR, textStatus,
                             errorMessage) { iconCreationError(errorMessage); },
            complete : loadingFinished
          })
        } else {
          canvas.toBlob(function(blob) {
            saveAs(blob, "favicon.png");
            loadingFinished();
          });
        }
      }
    });

    $("#stacked").click(function() {
      stackedSelected = this.checked;
      this.checked ? $stackedSize.show() : $stackedSize.hide();
      draw();
    });

    $.each(icons, function(index, icon) {
      var $iconOuter = $("<div>").addClass("icon_outer").data("id", icon.id);

      var iconStyle;
      switch (icon.style) {
      case 'solid':
        iconStyle = 's';
        break;
      case 'regular':
        iconStyle = 'r';
        break;
      default:
        console.error('Unkown icon style.');
      }
      var styleClass = "fa" + iconStyle + " fa-" + icon.id;
      var $icon = $("<div>")
                      .addClass("icon hover")
                      .data('style', iconStyle)
                      .data('unicode', icon.unicode)
                      .append($('<i>').addClass(styleClass));
      $icon.append($("<div>").addClass("icon_text underline").text(icon.id));
      $iconOuter.append($icon);
      $right.append($iconOuter);
    });

    $(".icon").on("click touchstart", function() {
      var selectedSymbol = $(this).data('unicode');
      var selectedSymbolStyle = $(this).data('style');
      if (stackedSelected) {
        stackedSymbol = selectedSymbol;
        stackedSymbolStyle = selectedSymbolStyle;
      } else {
        symbol = selectedSymbol;
        symbolStyle = selectedSymbolStyle;
      }
      draw();
    });

    $("#file_format").on("click", function() {
      new_format = ".ico";
      if ($fileFormatText.text() == ".ico") {
        new_format = ".png";
      }
      $fileFormatText.text(new_format);
    });

    setTimeout(draw, 1000);
  }

  function initSearch($search, $right) {
    var options = {
      id : "id",
      shouldSort : true,
      threshold : 0.3,
      location : 0,
      distance : 100,
      maxPatternLength : 32,
      minMatchCharLength : 1,
      keys : [ "id", "name", "search_terms" ]
    };
    var fuse = new Fuse(icons, options);
    $search.on("input", function() {
      var query = $search.get(0).value;
      var result = fuse.search(query);
      $right.children().hide();
      $right.children()
          .filter(function(index, element) {
            return query == "" || result.indexOf($(element).data("id")) != -1;
          })
          .show();
      if (result.length == 0 && query != "") {
        tinysort($right.children());
      } else if (result.length > 0) {
        tinysort($right.children(), {
{'fraction_non_alphanumeric': 0.16038664637966527, 'fraction_numerical': 0.008950147677436678, 'mean_word_length': 2.2874374816122387, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4244471', 'n_tokens_mistral': 3329, 'n_tokens_neox': 3204, 'n_words': 648}