Sha256: a1dddbdf54a41adb1626562374e4fb729907f19102b0430f3511dbd143fe85b1

Contents?: true

Size: 1.46 KB

Versions: 26

Compression:

Stored size: 1.46 KB

Contents

// https://github.com/javierjulio/textarea-autosize
/*!
 * jQuery Textarea AutoSize plugin
 * Author: Javier Julio
 * Licensed under the MIT license
 */
;(function ($, window, document, undefined) {

  var pluginName = "textareaAutoSize";
  var pluginDataName = "plugin_" + pluginName;

  var containsText = function (value) {
    return (value.replace(/\s/g, '').length > 0);
  };

  function Plugin(element, options) {
    this.element = element;
    this.$element = $(element);
    this.init();
  }

  Plugin.prototype = {
    init: function() {
      var height = this.$element.outerHeight();
      var diff = parseInt(this.$element.css('paddingBottom')) +
                  parseInt(this.$element.css('paddingTop'));

      if (containsText(this.element.value)) {
        this.$element.height(this.element.scrollHeight - diff);
      }

      // keyup is required for IE to properly reset height when deleting text
      this.$element.on('input keyup', function(event) {
        var $scrollParent = $(this).scrollParent();
        var currentScrollPosition = $scrollParent.scrollTop();

        $(this)
          .height(0)
          .height(this.scrollHeight - diff);

        $scrollParent.scrollTop(currentScrollPosition);
      });
    }
  };

  $.fn[pluginName] = function (options) {
    this.each(function() {
      if (!$.data(this, pluginDataName)) {
        $.data(this, pluginDataName, new Plugin(this, options));
      }
    });
    return this;
  };

})(jQuery, window, document);

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
formagic-0.3.10 app/assets/javascripts/vendor/jquery.textarea_autosize.js
formagic-0.3.9 app/assets/javascripts/vendor/jquery.textarea_autosize.js
formagic-0.3.8 app/assets/javascripts/vendor/jquery.textarea_autosize.js
formagic-0.3.7 app/assets/javascripts/vendor/jquery.textarea_autosize.js
formagic-0.3.4 app/assets/javascripts/vendor/jquery.textarea_autosize.js
formagic-0.3.3 app/assets/javascripts/vendor/jquery.textarea_autosize.js
formagic-0.3.2 app/assets/javascripts/vendor/jquery.textarea_autosize.js
formagic-0.3.1 app/assets/javascripts/vendor/jquery.textarea_autosize.js
formagic-0.3.0 app/assets/javascripts/vendor/jquery.textarea_autosize.js
formagic-0.2.9 app/assets/javascripts/vendor/jquery.textarea_autosize.js
formagic-0.2.8 app/assets/javascripts/vendor/jquery.textarea_autosize.js
formagic-0.2.6 app/assets/javascripts/vendor/jquery.textarea_autosize.js
formagic-0.2.5 app/assets/javascripts/vendor/jquery.textarea_autosize.js
formagic-0.1.0 app/assets/javascripts/vendor/jquery.textarea_autosize.js
chr-0.3.5 app/assets/javascripts/vendor/jquery.textarea_autosize.js
chr-0.2.8 app/assets/javascripts/chr/vendor/jquery.textarea_autosize.js
chr-0.2.7 app/assets/javascripts/chr/vendor/jquery.textarea_autosize.js
chr-0.2.5 app/assets/javascripts/chr/vendor/jquery.textarea_autosize.js
chr-0.2.4 app/assets/javascripts/chr/vendor/jquery.textarea_autosize.js
chr-0.2.1 app/assets/javascripts/chr/vendor/jquery.textarea_autosize.js