2  * ----------------------------------------------------------------------------
 
   3  * "THE BEER-WARE LICENSE" (Revision 42):
 
   4  * <jevin9@gmail.com> wrote this file. As long as you retain this notice you
 
   5  * can do whatever you want with this stuff. If we meet some day, and you think
 
   6  * this stuff is worth it, you can buy me a beer in return. Jevin O. Sewaruth
 
   7  * ----------------------------------------------------------------------------
 
   9  * Autogrow Textarea Plugin Version v3.0
 
  10  * http://www.technoreply.com/autogrow-textarea-plugin-3-0
 
  12  * THIS PLUGIN IS DELIVERD ON A PAY WHAT YOU WHANT BASIS. IF THE PLUGIN WAS USEFUL TO YOU, PLEASE CONSIDER BUYING THE PLUGIN HERE :
 
  13  * https://sites.fastspring.com/technoreply/instant/autogrowtextareaplugin
 
  15  * Date: October 15, 2012
 
  18 jQuery.fn.autoGrow = function() {
 
  19         return this.each(function() {
 
  21                 var createMirror = function(textarea) {
 
  22                         jQuery(textarea).after('<div class="autogrow-textarea-mirror"></div>');
 
  23                         return jQuery(textarea).next('.autogrow-textarea-mirror')[0];
 
  26                 var sendContentToMirror = function (textarea) {
 
  27                         mirror.innerHTML = String(textarea.value).replace(/&/g, '&').replace(/"/g, '"').replace(/'/g, ''').replace(/</g, '<').replace(/>/g, '>').replace(/\n/g, '<br />') + '.<br/>.';
 
  29                         if (jQuery(textarea).height() != jQuery(mirror).height())
 
  30                                 jQuery(textarea).height(jQuery(mirror).height());
 
  33                 var growTextarea = function () {
 
  34                         sendContentToMirror(this);
 
  38                 var mirror = createMirror(this);
 
  41                 mirror.style.display = 'none';
 
  42                 mirror.style.wordWrap = 'break-word';
 
  43                 mirror.style.padding = jQuery(this).css('padding');
 
  44                 mirror.style.width = jQuery(this).css('width');
 
  45                 mirror.style.fontFamily = jQuery(this).css('font-family');
 
  46                 mirror.style.fontSize = jQuery(this).css('font-size');
 
  47                 mirror.style.lineHeight = jQuery(this).css('line-height');
 
  50                 this.style.overflow = "hidden";
 
  51                 this.style.minHeight = this.rows+"em";
 
  53                 // Bind the textarea's event
 
  54                 this.onkeyup = growTextarea;
 
  56                 // Fire the event for text already present
 
  57                 sendContentToMirror(this);