Sha256: 1cfdd2195a802bb40137c48c8adf0d0b6cd18a8eaa31858ffe7bd388c7dea1dc
Contents?: true
Size: 1.41 KB
Versions: 3
Compression:
Stored size: 1.41 KB
Contents
(function($) { /* * Auto-growing textareas */ $.fn.autogrow = function(options) { this.filter('textarea').each(function() { var $this = $(this), minHeight = $this.outerHeight(), lineHeight = $this.css('lineHeight'); var shadow = $('<div></div>').css({ position: 'absolute', top: -10000, left: -10000, width: $(this).width() - parseInt($this.css('paddingLeft')) - parseInt($this.css('paddingRight')), fontSize: $this.css('fontSize'), fontFamily: $this.css('fontFamily'), lineHeight: $this.css('lineHeight'), resize: 'none' }).appendTo(document.body); var update = function() { var times = function(string, number) { var _res = ''; for(var i = 0; i < number; i ++) { _res = _res + string; } return _res; }; var val = this.value.replace(/</g, '<') .replace(/>/g, '>') .replace(/&/g, '&') .replace(/\n$/, '<br/> ') .replace(/\n/g, '<br/>') .replace(/ {2,}/g, function(space) { return times(' ', space.length -1) + ' ' }); shadow.html(val); $(this).css('height', Math.max(shadow.outerHeight() + 20, minHeight)); } $(this).change(update).keyup(update).keydown(update); update.apply(this); }); return this; } })(jQuery);
Version data entries
3 entries across 3 versions & 1 rubygems