1 line
1.3 KiB
JavaScript
1 line
1.3 KiB
JavaScript
(function(a){a.fn.autogrow=function(e){var d=a(this).css({overflow:"hidden",resize:"none"}),b=d.selector,f={context:a(document),animate:false,speed:200,fixMinHeight:true,cloneClass:"autogrowclone",onInitialize:true};e=a.isPlainObject(e)?e:{context:e?e:a(document)};e=a.extend({},f,e);d.each(function(h,j){var g,k;j=a(j);if(j.is(":visible")||parseInt(j.css("height"),10)>0){g=parseInt(j.css("height"),10)||j.innerHeight()}else{k=j.clone().addClass(e.cloneClass).val(j.val()).css({position:"absolute",visibility:"hidden",display:"block"});a("body").append(k);g=k.innerHeight();k.remove()}if(e.fixMinHeight){j.data("autogrow-start-height",g)}j.css("height",g)});e.context.on("keyup paste",b,c);if(e.onInitialize){d.trigger("keyup")}function c(j){var h=a(this),l=h.innerHeight(),g=this.scrollHeight,i=h.data("autogrow-start-height")||0,k;if(l<g){this.scrollTop=0;e.animate?h.stop().animate({height:g},e.speed):h.innerHeight(g)}else{if(!j||j.which===8||j.which===46||(j.ctrlKey&&j.which===88)){if(l>i){k=h.clone().addClass(e.cloneClass).css({position:"absolute",zIndex:-10}).val(h.val());h.after(k);do{g=k[0].scrollHeight-1;k.innerHeight(g)}while(g===k[0].scrollHeight);g++;k.remove();h.focus();g<i&&(g=i);l>g&&e.animate?h.stop().animate({height:g},e.speed):h.innerHeight(g)}else{h.innerHeight(i)}}}}return d}})(jQuery); |