/*! * flexibleArea.js v1.0 * A jQuery plugin that dynamically updates textarea's height to fit the content. * http://flaviusmatis.github.com/flexibleArea.js/ * * Copyright 2012, Flavius Matis * Released under the MIT license. * http://flaviusmatis.github.com/license.html */ (function($){ var methods = { init : function() { var styles = [ 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', 'fontSize', 'lineHeight', 'fontFamily', 'width', 'fontWeight', 'border-top-width', 'border-right-width', 'border-bottom-width', 'border-left-width' ]; return this.each( function() { if (this.type !== 'textarea') return false; var $textarea = $(this).css({'resize': 'none', overflow: 'hidden'}); var $clone = $('
').css({ 'position' : 'absolute', 'display' : 'none', 'word-wrap' : 'break-word', 'white-space' : 'pre-wrap', 'border-style' : 'solid' }).appendTo(document.body); // Apply textarea styles to clone for (var i=0; i < styles.length; i++) { $clone.css(styles[i],$textarea.css(styles[i])); } var textareaHeight = parseInt($textarea.css('height'), 10); var lineHeight = parseInt($textarea.css('line-height'), 10) || parseInt($textarea.css('font-size'), 10); var minheight = lineHeight * 2 > textareaHeight ? lineHeight * 2 : textareaHeight; var maxheight = parseInt($textarea.css('max-height'), 10) > -1 ? parseInt($textarea.css('max-height'), 10) : Number.MAX_VALUE; function updateHeight() { var textareaContent = $textarea.val().replace(//g, '>').replace(/&/g, '&').replace(/\n/g, '