<commit_before>/* Based on http://stackoverflow.com/questions/7477/autosizing-textarea/948445#948445 Heavily modified by <NAME> */

if (window.Widget == undefined)
{
  window.Widget = {}; 
}

Widget.Textarea = Class.create(
{
  initialize: function(textarea, options)
  {
    this.textarea = $(textarea);
    this.options = $H(
    {
      'min_height'  : 30,
       'max_length' : 400
    }).update(options);
    
    this.textarea.setStyle(
    {
      overflow : 'hidden',
      lineHeight : '18px'
    });

    this.textarea.observe('keyup', this.refresh.bind(this));

    this._shadow = new Element('div').setStyle(
    {
      lineHeight : this.textarea.getStyle('lineHeight'),
      fontSize : this.textarea.getStyle('fontSize'),
      fontFamily : this.textarea.getStyle('fontFamily'),
      position : 'absolute',
      top: '-10000px',
      left: '-10000px',
      width: this.textarea.getWidth() + 'px'
    });
    
    this.textarea.insert(
    { 
      after: this._shadow 
    });

    this._remainingCharacters = new Element('p').addClassName('remainingCharacters');
    this.textarea.insert(
    {
      after: this._remainingCharacters
    });  
    this.refresh();  
  },

  refresh: function()
  { 
    this._shadow.update($F(this.textarea).replace(/\n/g, '<br/>'));
    this.textarea.setStyle(
    {
      height: Math.max(parseInt(this._shadow.getHeight()) + parseInt(this.textarea.getStyle('lineHeight').replace('px', '')), this.options.get('min_height')) + 'px'
    });
    
    console.log(this._shadow.getHeight());
    console.log(this.textarea.getStyle('lineHeight').replace('px', ''));
    console.log(this.options.get('min_height'));
    
    

    var remaining = this.options.get('max_length') - $F(this.textarea).length;
    this._remainingCharacters.update(Math.abs(remaining)  + ' characters ' + (remaining > 0 ? 'remaining' : 'over the limit'));
  }
});


/* Create widgets for resizing our textareas when the page is loaded */

document.observe('dom:loaded', function() 
{
  
  $$('textarea').each(function(textarea) 
  {
    new Widget.Textarea(textarea);
  });  
     
});

<commit_msg>removed the remaining character count from the example code<commit_after>/* Based on http://stackoverflow.com/questions/7477/autosizing-textarea/948445#948445 Heavily modified by <NAME> */

if (window.Widget == undefined)
{
  window.Widget = {}; 
}

Widget.Textarea = Class.create(
{
  initialize: function(textarea, options)
  {
    this.textarea = $(textarea);
    this.options  = $H(
    {
      'min_height'  : 280,
       'max_length' : 400
    }).update(options);
    
    this.textarea.setStyle(
    {
      overflow    : 'hidden',
      lineHeight  : '18px'

    });

    this.textarea.observe('keyup', this.refresh.bind(this));

    this._shadow = new Element('div').setStyle(
    {
      lineHeight  : this.textarea.getStyle('lineHeight'),
      fontSize    : this.textarea.getStyle('fontSize'),
      fontFamily  : this.textarea.getStyle('fontFamily'),
      position    : 'absolute',
      top         : '-10000px',
      left        : '-10000px',
      width       : this.textarea.getWidth() + 'px'
    });
    
    this.textarea.insert(
    { 
      after: this._shadow 
    });

    this.refresh();  
  },

  refresh: function()
  { 
    this._shadow.update($F(this.textarea).replace(/\n/g, '<br/>'));
    this.textarea.setStyle(
    {
      height: Math.max(parseInt(this._shadow.getHeight()) + parseInt(this.textarea.getStyle('lineHeight').replace('px', '')), this.options.get('min_height')) + 'px'
    });
  }
});


/* Create widgets for resizing our textareas when the page is loaded */
document.observe('dom:loaded', function() 
{
  $$('textarea').each(function(textarea) 
  {
    new Widget.Textarea(textarea);
  });  
});
{'fraction_non_alphanumeric': 0.16825902335456475, 'fraction_numerical': 0.018046709129511677, 'mean_word_length': 2.913811007268951, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, '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': '5756978', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1199, 'n_words': 191}