<commit_before>function YNAutocompleteInput( meta_span )
{
  select             = $(meta_span).siblings('select').get(0);
  this.base_id       = select.id;
  this.name          = select.name;
  this.multiple      = select.multiple;
  this.state         = [];
  this.initial_value = {};

  this.edit_button   = null;
  this.delete_button = null;

  this.container = $(meta_span).parent();
  this.metadata  = $.parseJSON( meta_span.title );
}

YNAutocompleteInput.prototype.init = function()
{
  this.input           = document.createElement( 'input' );
  this.input.id        = this.base_id + '_autocomplete';
  this.input.className = 'yn-autocomplete';

  for ( name in this.metadata.attributes ) {
    this.input.setAttribute( name, this.metadata.attributes[ name ] );
  }

  // hard-coded defaults
  options = {
    source:    this.metadata.source,
    delay:     300,
    minLength: 3
  };

  // merge default options with provided options
  $.extend( options, this.metadata.options );

  // collect selected <option>s and transform into widget choices
  $('#' + this.base_id + ' option[selected="selected"]').each(
    yn_autocomplete_set_initial_value( this )
  );

  $('#' + this.base_id).remove();

  if ( ! this.multiple ) {
    this.edit_button           = document.createElement( 'span' );
    this.edit_button.id        = this.base_id + '_edit';
    this.edit_button.title     = 'Edit';
    this.edit_button.className = 'ui-icon ui-icon-pencil yn-autocomplete-edit-button';

    $(this.edit_button).prependTo( this.container )
                       .click( yn_autocomplete_single_redirect( this ) );

    this.delete_button           = document.createElement( 'span' );
    this.delete_button.id        = this.base_id + '_delete';
    this.delete_button.title     = 'Clear';
    this.delete_button.className = 'ui-icon ui-icon-close yn-autocomplete-delete-button';

    $(this.delete_button).prependTo( this.container )
                         .click( yn_autocomplete_single_clear( this ) );

    this.update_single_buttons();
  }

  $(this.input).prependTo( this.container );

  if ( this.multiple ) {
    this.init_ul();

    options.select = yn_autocomplete_multiple_select( this );
    options.close  = function( e, ui ) {e.target.value = ''};

    $(this.input).autocomplete( options );
  }
  else {
    options.select = yn_autocomplete_single_select( this );
    options.change = yn_autocomplete_single_change( this );

    $(this.input).autocomplete( options )
                 .addClass('yn-autocomplete-single')
                 .focus( function() {this.value = '';} );

    this.input.last_known_value = this.input.value;
    
    clear = document.createElement( 'div' );
    clear.className = 'yn-autocomplete-clear';
    $(clear).appendTo( this.container );
  }

  $($(this.input).parents('form').get(0))
    .submit( yn_autocomplete_form_preprocess( this ) );
}

YNAutocompleteInput.prototype.init_ul = function() {
  this.ul           = document.createElement('ul');
  this.ul.id        = this.base_id + '_items';
  this.ul.className = 'yn-autocomplete-selected-list';

  $(this.ul).appendTo( this.container );

  for ( key in this.initial_value ) {
    this.add_li( key, this.initial_value[ key ], false );
  }
}

YNAutocompleteInput.prototype.add_li = function( key, value, animate ) {
  c_span = document.createElement('span');
  c_span.className = 'ui-icon ui-icon-close';

  b_div = document.createElement('div');
  b_div.className = 'ui-state-default ui-corner-all ';
  b_div.id = this.ul.id + '_' + key + '_remove';
  b_div.appendChild( c_span );

  $(b_div).click( yn_autocomplete_item_click( this, key ) );

  a_li = document.createElement('li');
  a_li.id = this.ul.id + '_' + key;
  a_li.appendChild( b_div );
  
  text = document.createTextNode( value );

  if ( this.metadata.item_route ) {
    url = this.metadata.item_route + '?id=' + key;
    link = document.createElement( 'a' );
    link.href = url;<commit_msg>add another item_route translation<commit_after>function YNAutocompleteInput( meta_span )
{
  select             = $(meta_span).siblings('select').get(0);
  this.base_id       = select.id;
  this.name          = select.name;
  this.multiple      = select.multiple;
  this.state         = [];
  this.initial_value = {};

  this.edit_button   = null;
  this.delete_button = null;

  this.container = $(meta_span).parent();
  this.metadata  = $.parseJSON( meta_span.title );
}

YNAutocompleteInput.prototype.init = function()
{
  this.input           = document.createElement( 'input' );
  this.input.id        = this.base_id + '_autocomplete';
  this.input.className = 'yn-autocomplete';

  for ( name in this.metadata.attributes ) {
    this.input.setAttribute( name, this.metadata.attributes[ name ] );
  }

  // hard-coded defaults
  options = {
    source:    this.metadata.source,
    delay:     300,
    minLength: 3
  };

  // merge default options with provided options
  $.extend( options, this.metadata.options );

  // collect selected <option>s and transform into widget choices
  $('#' + this.base_id + ' option[selected="selected"]').each(
    yn_autocomplete_set_initial_value( this )
  );

  $('#' + this.base_id).remove();

  if ( ! this.multiple ) {
    this.edit_button           = document.createElement( 'span' );
    this.edit_button.id        = this.base_id + '_edit';
    this.edit_button.title     = 'Edit';
    this.edit_button.className = 'ui-icon ui-icon-pencil yn-autocomplete-edit-button';

    $(this.edit_button).prependTo( this.container )
                       .click( yn_autocomplete_single_redirect( this ) );

    this.delete_button           = document.createElement( 'span' );
    this.delete_button.id        = this.base_id + '_delete';
    this.delete_button.title     = 'Clear';
    this.delete_button.className = 'ui-icon ui-icon-close yn-autocomplete-delete-button';

    $(this.delete_button).prependTo( this.container )
                         .click( yn_autocomplete_single_clear( this ) );

    this.update_single_buttons();
  }

  $(this.input).prependTo( this.container );

  if ( this.multiple ) {
    this.init_ul();

    options.select = yn_autocomplete_multiple_select( this );
    options.close  = function( e, ui ) {e.target.value = ''};

    $(this.input).autocomplete( options );
  }
  else {
    options.select = yn_autocomplete_single_select( this );
    options.change = yn_autocomplete_single_change( this );

    $(this.input).autocomplete( options )
                 .addClass('yn-autocomplete-single')
                 .focus( function() {this.value = '';} );

    this.input.last_known_value = this.input.value;
    
    clear = document.createElement( 'div' );
    clear.className = 'yn-autocomplete-clear';
    $(clear).appendTo( this.container );
  }

  $($(this.input).parents('form').get(0))
    .submit( yn_autocomplete_form_preprocess( this ) );
}

YNAutocompleteInput.prototype.init_ul = function() {
  this.ul           = document.createElement('ul');
  this.ul.id        = this.base_id + '_items';
  this.ul.className = 'yn-autocomplete-selected-list';

  $(this.ul).appendTo( this.container );

  for ( key in this.initial_value ) {
    this.add_li( key, this.initial_value[ key ], false );
  }
}

YNAutocompleteInput.prototype.add_li = function( key, value, animate ) {
  c_span = document.createElement('span');
  c_span.className = 'ui-icon ui-icon-close';

  b_div = document.createElement('div');
  b_div.className = 'ui-state-default ui-corner-all ';
  b_div.id = this.ul.id + '_' + key + '_remove';
  b_div.appendChild( c_span );

  $(b_div).click( yn_autocomplete_item_click( this, key ) );

  a_li = document.createElement('li');
  a_li.id = this.ul.id + '_' + key;
  a_li.appendChild( b_div );
  
  text = document.createTextNode( value );

  var url;

  if ( this.metadata.item_route ) {
    if ( this.metadata.item_route.indexOf( '999999' ) == -1 ) {
      url = this.metadata.item_route + '?id=' + key;
    }
    else {
      url = this.metadata.item_route.replace('999999', key);
    }
    
    link = document.createElement( 'a' );
    link.href = url;
{'fraction_non_alphanumeric': 0.14679012345679013, 'fraction_numerical': 0.0030864197530864196, 'mean_word_length': 2.921103581800581, 'pattern_counts': {'":': 0, '<': 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': '3674266', 'n_tokens_mistral': 2709, 'n_tokens_neox': 2594, 'n_words': 442}