diff --git a/autogrow.jquery.json b/autogrow.jquery.json index 3d22727..a9fdfa4 100644 --- a/autogrow.jquery.json +++ b/autogrow.jquery.json @@ -1,6 +1,6 @@ { "name": "autogrow" - , "version": "1.0.2" + , "version": "1.0.3" , "title": "autogrow.js" , "author": { "name": "Jason Edelman" @@ -20,4 +20,4 @@ , "homepage": "https://github.com/ultimatedelman/autogrow" , "docs": "https://github.com/ultimatedelman/autogrow" , "demo": "http://jsfiddle.net/edelman/HrnHb/" -} \ No newline at end of file +} diff --git a/autogrow.js b/autogrow.js index 81ca1e7..4a691f5 100644 --- a/autogrow.js +++ b/autogrow.js @@ -40,14 +40,14 @@ } elem.css('height', min); - if (opts.onInitialize) { - resize.call(elem); + if (opts.onInitialize && elem.length) { + resize.call(elem[0]); } }); opts.context .on('keyup paste', selector, resize) ; - + function resize (e){ var box = $(this) , oldHeight = box.innerHeight() @@ -72,9 +72,12 @@ //doing this on an exact clone to figure out the height first and then applying it to the //actual box makes it look cleaner to the user clone = box.clone() - .addClass(opts.cloneClass) //add clone class for extra css rules - .css({position: 'absolute', zIndex:-10}) //make "invisible" - .val(box.val()) //populate with content for consistent measuring + //add clone class for extra css rules + .addClass(opts.cloneClass) + //make "invisible", remove height restriction potentially imposed by existing CSS + .css({position: 'absolute', zIndex:-10, height: ''}) + //populate with content for consistent measuring + .val(box.val()) ; box.after(clone); //append as close to the box as possible for best CSS matching for clone do { //reduce height until they don't match @@ -112,5 +115,7 @@ function notifyShrunk() { opts.context.trigger('autogrow:shrink'); } + + return that; } })(jQuery); diff --git a/autogrow.min.js b/autogrow.min.js index 3738036..72a60ce 100644 --- a/autogrow.min.js +++ b/autogrow.min.js @@ -1,5 +1,5 @@ /* -autogrow.js - Copyright (C) 2013, Jason Edelman +autogrow.js - Copyright (C) 2014, Jason Edelman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including @@ -15,4 +15,4 @@ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABI CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -;(function(e){e.fn.autogrow=function(t){function s(n){var r=e(this),i=r.innerHeight(),s=this.scrollHeight,o=r.data("autogrow-start-height")||0,u;if(io){u=r.clone().addClass(t.cloneClass).css({position:"absolute",zIndex:-10}).val(r.val());r.after(u);do{s=u[0].scrollHeight-1;u.innerHeight(s)}while(s===u[0].scrollHeight);s++;u.remove();ss&&t.animate?r.stop().animate({height:s},t.speed):r.innerHeight(s)}else{r.innerHeight(o)}}}var n=e(this).css({overflow:"hidden",resize:"none"}),r=n.selector,i={context:e(document),animate:true,speed:200,fixMinHeight:true,cloneClass:"autogrowclone",onInitialize:false};t=e.isPlainObject(t)?t:{context:t?t:e(document)};t=e.extend({},i,t);n.each(function(n,r){var i,o;r=e(r);if(r.is(":visible")||parseInt(r.css("height"),10)>0){i=parseInt(r.css("height"),10)||r.innerHeight()}else{o=r.clone().addClass(t.cloneClass).val(r.val()).css({position:"absolute",visibility:"hidden",display:"block"});e("body").append(o);i=o.innerHeight();o.remove()}if(t.fixMinHeight){r.data("autogrow-start-height",i)}r.css("height",i);if(t.onInitialize){s.call(r)}});t.context.on("keyup paste",r,s)}})(jQuery); +;(function(e){e.fn.autogrow=function(t){function s(n){var r=e(this),i=r.innerHeight(),s=this.scrollHeight,o=r.data("autogrow-start-height")||0,u;if(io){u=r.clone().addClass(t.cloneClass).css({position:"absolute",zIndex:-10,height:""}).val(r.val());r.after(u);do{s=u[0].scrollHeight-1;u.innerHeight(s)}while(s===u[0].scrollHeight);s++;u.remove();r.focus();ss&&t.animate?r.stop().animate({height:s},t.speed):r.innerHeight(s)}else{r.innerHeight(o)}}}var n=e(this).css({overflow:"hidden",resize:"none"}),r=n.selector,i={context:e(document),animate:true,speed:200,fixMinHeight:true,cloneClass:"autogrowclone",onInitialize:false};t=e.isPlainObject(t)?t:{context:t?t:e(document)};t=e.extend({},i,t);n.each(function(n,r){var i,o;r=e(r);if(r.is(":visible")||parseInt(r.css("height"),10)>0){i=parseInt(r.css("height"),10)||r.innerHeight()}else{o=r.clone().addClass(t.cloneClass).val(r.val()).css({position:"absolute",visibility:"hidden",display:"block"});e("body").append(o);i=o.innerHeight();o.remove()}if(t.fixMinHeight){r.data("autogrow-start-height",i)}r.css("height",i);if(t.onInitialize&&r.length){s.call(r[0])}});t.context.on("keyup paste",r,s);return n}})(jQuery); diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..ed2faa6 --- /dev/null +++ b/bower.json @@ -0,0 +1,15 @@ +{ + "name": "autogrow", + "description": "Automatically grow and shrink textareas with the content as you type.", + "version": "1.0.4", + "main": "./autogrow.js", + "author": { + "name": "Jason Edelman", + "url": "http://jasonedelman.com" + }, + "dependencies": { + "jquery": ">=1.7" + }, + "keywords": ["textarea", "grow", "shrink", "resize"], + "homepage": "https://github.com/ultimatedelman/autogrow" +}