-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathjquery.auto-grow-input.min.js
More file actions
3 lines (3 loc) · 1.01 KB
/
jquery.auto-grow-input.min.js
File metadata and controls
3 lines (3 loc) · 1.01 KB
1
2
3
// jQuery autoGrowInput v1.0.3
// https://github.com/Pixabay/jQuery-autoGrowInput
!function(t){var n="oninput"in document.createElement("input")?"input":"keydown";t.fn.autoGrowInput=function(o){var e=t.extend({maxWidth:500,minWidth:20,comfortZone:0},o);return this.each(function(){var i=t(this),a=" ",r=o&&"comfortZone"in o?e.comfortZone:parseInt(i.css("fontSize")),c=t("<span/>").css({position:"absolute",top:-9999,left:-9999,width:"auto",fontSize:i.css("fontSize"),fontFamily:i.css("fontFamily"),fontWeight:i.css("fontWeight"),letterSpacing:i.css("letterSpacing"),textTransform:i.css("textTransform"),whiteSpace:"nowrap",ariaHidden:!0}).appendTo("body"),s=function(t){if(a!==(a=i.val())||"autogrow"===t.type){a||(a=i.attr("placeholder")||""),c.html(a.replace(/&/g,"&").replace(/\s/g," ").replace(/</g,"<").replace(/>/g,">"));var n=c.width()+r,o="function"==typeof e.maxWidth?e.maxWidth():e.maxWidth;n>o?n=o:n<e.minWidth&&(n=e.minWidth),n!=i.width()&&i.width(n)}};i.on(n+".autogrow autogrow",s),s()}),this}}(jQuery);