<commit_before>$(document).ready(function () {

  var wymconfig = {
    skin: 'custom',
    toolsItems: [
      {'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong'}, 
      {'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis'},
      {'name': 'InsertOrderedList', 'title': 'Ordered_List', 'css': 'wym_tools_ordered_list'},
      {'name': 'InsertUnorderedList', 'title': 'Unordered_List', 'css': 'wym_tools_unordered_list'},
      {'name': 'Undo', 'title': 'Undo', 'css': 'wym_tools_undo'},
      {'name': 'Redo', 'title': 'Redo', 'css': 'wym_tools_redo'},
      {'name': 'CreateLink', 'title': 'Link', 'css': 'wym_tools_link'},
      {'name': 'Unlink', 'title': 'Unlink', 'css': 'wym_tools_unlink'},
      {'name': 'ToggleHtml', 'title': 'HTML', 'css': 'wym_tools_html'}
    ],
    updateSelector: 'input:submit',
    updateEvent: 'click',
    classesHtml: ''
  };

  // Initialize WYMeditors.
  $('textarea').filter(function() {
    // Skip the hidden template form.
    return (! this.id.match(/__prefix__/))
  }).wymeditor(wymconfig);

  // Initialize timeago.
  $('time.timeago').timeago();

  // Initialize autocomplete fields.
  function init_autocomplete(collection, label_field, multiple) {
    return (function() {
      $('<input type="text" class="vTextField"></input>')
      .insertBefore($(this))
      .autocomplete({
        source: function(request, response) {
          $.getJSON('/api/' + collection + '/', { q: request.term }, 
                    function(data) {
                      response($.map(data, function(item, index) {
                        return { label: item[label_field], id: item.id };
                      }));
                    });
        },
        minLength: 2,
        focus: function() {
          return false;
        },
        select: function(event, ui) {
          if (ui.item) {
            var hidden = $(this).next();
            if (multiple) {
              var values = []
              if (hidden.val() !== '') {
                values = hidden.val().split(',');
              }
              values.push(ui.item.id);
              hidden.val(values.join(','));
              var choices = hidden.parent().find('ul.choices-display');
              var kill = $('<a class="remove-choice">Remove</a>');
              $('<li>' + ui.item.label + '</li>').appendTo(choices).prepend(kill);
              kill.bind('click', function(event) {
                values = hidden.val().split(',');
                for (var i = 0; i < values.length; i++) {
                  if (values[i] == ui.item.id) { break; }
                }
                values.splice(i, 1);
                hidden.val(values.join(','));
                $(this).parent().remove();
              });
              ui.item.value = '';
            } else {
              hidden.val(ui.item.id);
            }
          }
        }
      });
      if (multiple) {
        $(this).parent().append('<ul class="choices-display"></ul>')
      }
    });
  }

  function update_autocomplete(collection, label_field, multiple) {
    return (function() {
      var hidden = $(this);
      if (hidden.val()) {
        var autocomplete = hidden.prev();
        $.getJSON('/api/' + collection + '/' + hidden.val() + '/', {}, function(data) {
          if (multiple) {
            var choices = hidden.parent().find('ul.choices-display');
            if (! $.isArray(data)) {
              data = [ data ];
            }
            $.each(data, function() {
              var item = this;
              var kill = $('<a class="remove-choice">Remove</a>');
              $('<li>' + item[label_field] + '</li>').appendTo(choices).prepend(kill);
              kill.bind('click', function(event) {
                var values = hidden.val().split(',');
                for (var i = 0; i < values.length; i++) {
                  if (values[i] == item.id) { break; }
                }
                values.splice(i, 1);
                hidden.val(values.join(','));
                $(this).parent().remove();
              });
            });
          } else {
            autocomplete.val(data[label_field]);
          }
        });
      }
    });
  }<commit_msg>Fix bug with parsing topic JSON.<commit_after>$(document).ready(function () {

  var wymconfig = {
    skin: 'custom',
    toolsItems: [
      {'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong'}, 
      {'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis'},
      {'name': 'InsertOrderedList', 'title': 'Ordered_List', 'css': 'wym_tools_ordered_list'},
      {'name': 'InsertUnorderedList', 'title': 'Unordered_List', 'css': 'wym_tools_unordered_list'},
      {'name': 'Undo', 'title': 'Undo', 'css': 'wym_tools_undo'},
      {'name': 'Redo', 'title': 'Redo', 'css': 'wym_tools_redo'},
      {'name': 'CreateLink', 'title': 'Link', 'css': 'wym_tools_link'},
      {'name': 'Unlink', 'title': 'Unlink', 'css': 'wym_tools_unlink'},
      {'name': 'ToggleHtml', 'title': 'HTML', 'css': 'wym_tools_html'}
    ],
    updateSelector: 'input:submit',
    updateEvent: 'click',
    classesHtml: ''
  };

  // Initialize WYMeditors.
  $('textarea').filter(function() {
    // Skip the hidden template form.
    return (! this.id.match(/__prefix__/))
  }).wymeditor(wymconfig);

  // Initialize timeago.
  $('time.timeago').timeago();

  // Initialize autocomplete fields.
  function init_autocomplete(collection, label_field, multiple) {
    return (function() {
      $('<input type="text" class="vTextField"></input>')
      .insertBefore($(this))
      .autocomplete({
        source: function(request, response) {
          $.getJSON('/api/' + collection + '/', { q: request.term }, 
                    function(data) {
                      response($.map(data, function(item, index) {
                        return { label: item[label_field], id: item.id };
                      }));
                    });
        },
        minLength: 2,
        focus: function() {
          return false;
        },
        select: function(event, ui) {
          if (ui.item) {
            var hidden = $(this).next();
            if (multiple) {
              var values = []
              if (hidden.val() !== '') {
                values = hidden.val().split(',');
              }
              values.push(ui.item.id);
              hidden.val(values.join(','));
              var choices = hidden.parent().find('ul.choices-display');
              var kill = $('<a class="remove-choice">Remove</a>');
              $('<li>' + ui.item.label + '</li>').appendTo(choices).prepend(kill);
              kill.bind('click', function(event) {
                values = hidden.val().split(',');
                for (var i = 0; i < values.length; i++) {
                  if (values[i] == ui.item.id) { break; }
                }
                values.splice(i, 1);
                hidden.val(values.join(','));
                $(this).parent().remove();
              });
              ui.item.value = '';
            } else {
              hidden.val(ui.item.id);
            }
          }
        }
      });
      if (multiple) {
        $(this).parent().append('<ul class="choices-display"></ul>')
      }
    });
  }

  function update_autocomplete(collection, label_field, multiple) {
    return (function() {
      var hidden = $(this);
      if (hidden.val()) {
        var autocomplete = hidden.prev();
        $.getJSON('/api/' + collection + '/' + hidden.val() + '/', {}, function(data) {
          if (! $.isArray(data)) {
            data = [ data ];
          }
          if (multiple) {
            var choices = hidden.parent().find('ul.choices-display');
            $.each(data, function() {
              var item = this;
              var kill = $('<a class="remove-choice">Remove</a>');
              $('<li>' + item[label_field] + '</li>').appendTo(choices).prepend(kill);
              kill.bind('click', function(event) {
                var values = hidden.val().split(',');
                for (var i = 0; i < values.length; i++) {
                  if (values[i] == item.id) { break; }
                }
                values.splice(i, 1);
                hidden.val(values.join(','));
                $(this).parent().remove();
              });
            });
          } else {
            autocomplete.val(data[0][label_field]);
          }
        });
      }
    });
  }
{'fraction_non_alphanumeric': 0.1911834600760456, 'fraction_numerical': 0.0013070342205323193, 'mean_word_length': 1.7824793388429752, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 27, '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': '3815550', 'n_tokens_mistral': 2533, 'n_tokens_neox': 2446, 'n_words': 465}