1/* 2 * Auto Expanding Text Area (1.2.2) 3 * by Chrys Bader (www.chrysbader.com) 4 * [email protected] 5 * 6 * Special thanks to: 7 * Jake Chapa - [email protected] 8 * John Resig - [email protected] 9 * 10 * Copyright (c) 2008 Chrys Bader (www.chrysbader.com) 11 * Licensed under the GPL (GPL-LICENSE.txt) license. 12 * 13 * 14 * NOTE: This script requires jQuery to work. Download jQuery at www.jquery.com 15 * 16 */ 17 18(function(jQuery) { 19 20 var self = null; 21 22 jQuery.fn.autogrow = function(o) 23 { 24 return this.each(function() { 25 new jQuery.autogrow(this, o); 26 }); 27 }; 28 29 30 /** 31 * The autogrow object. 32 * 33 * @constructor 34 * @name jQuery.autogrow 35 * @param Object e The textarea to create the autogrow for. 36 * @param Hash o A set of key/value pairs to set as configuration properties. 37 * @cat Plugins/autogrow 38 */ 39 40 jQuery.autogrow = function (e, o) 41 { 42 this.options = o || {}; 43 this.dummy = null; 44 this.interval = null; 45 this.line_height = this.options.lineHeight || parseInt(jQuery(e).css('line-height'));
46 this.min_height = this.options.minHeight || parseInt(jQuery(e).css('min-height')); 47 this.max_height = this.options.maxHeight || parseInt(jQuery(e).css('max-height'));; 48 this.textarea = jQuery(e); 49 if(!this.line_height) 50 this.line_height = 0; 51 // Only one textarea activated at a time, the one being used 52 this.init(); 53 }; 54 55 jQuery.autogrow.fn = jQuery.autogrow.prototype = { 56 autogrow: '1.2.2' 57 }; 58 59 jQuery.autogrow.fn.extend = jQuery.autogrow.extend = jQuery.extend; 60 61 jQuery.autogrow.fn.extend({ 62 63 init: function() { 64 var self = this; 65 this.textarea.css({overflow: 'hidden', display: 'block'}); 66 this.textarea.bind('focus', function() { self.startExpand() } ).bind('blur', function() { self.stopExpand() }); 67 this.checkExpand(); 68 }, 69 70 startExpand: function() { 71 var self = this; 72 this.interval = window.setInterval(function() {self.checkExpand()}, 400); 73 }, 74 75 stopExpand: function() { 76 clearInterval(this.interval); 77 }, 78 79 checkExpand: function() { 80 81 if (this.dummy == null) 82 { 83 this.dummy = jQuery('<div></div>'); 84 this.dummy.css({ 85 'font-size' : this.textarea.css('font-size'), 86 'font-family': this.textarea.css('font-family'), 87 'width' : this.textarea.css('width'), 88 'padding' : this.textarea.css('padding'), 89 'line-height': this.line_height + 'px', 90 'overflow-x' : 'hidden', 91 'position' : 'absolute', 92 'top' : 0, 93 'left' : -9999 94 }).appendTo('body'); 95 } 96 97 // Strip HTML tags 98 var html = this.textarea.val().replace(/(<|>)/g, ''); 99 100 // IE is different, as per usual 101 if ($.browser.msie) 102 { 103 html = html.replace(/\n/g, '<BR>new'); 104 } 105 else 106 { 107 html = html.replace(/\n/g, '<br>new'); 108 } 109 110 if (this.dummy.html() != html) 111 { 112 this.dummy.html(html); 113 114 if (this.max_height > 0 && (this.dummy.height() + this.line_height > this.max_height)) 115 { 116 this.textarea.css('overflow-y', 'auto'); 117 } 118 else 119 { 120 this.textarea.css('overflow-y', 'hidden'); 121 if ((this.textarea.height() < this.dummy.height() + this.line_height || (this.dummy.height() < this.textarea.height())) && (this.dummy.height() + this.line_height) > this.min_height) 122 { 123 this.textarea.animate({height: (this.dummy.height() + this.line_height) + 'px'}, 100); 124 } 125 } 126 } 127 } 128 129 }); 130})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.