Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions jquery.auto-grow-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
var event = 'oninput' in document.createElement('input') ? 'input' : 'keydown';

$.fn.autoGrowInput = function(options){
if (options === 'destroy') {
this.each(function() {
var input = $(this);
input.off(event + '.autogrow autogrow');
var span = input.data("autogrowSpan");
span.remove();
input.data('autogrowSpan','');
});

return this;
}

var o = $.extend({ maxWidth: 500, minWidth: 20, comfortZone: 0 }, options);

this.each(function(){
Expand Down Expand Up @@ -38,6 +50,7 @@
else if (newWidth < o.minWidth) newWidth = o.minWidth;
if (newWidth != input.width()) input.width(newWidth);
};
input.data("autogrowSpan", span);
input.on(event+'.autogrow autogrow', check);
// init on page load
check();
Expand Down