diff --git a/README.md b/README.md index 871a273..35c4cf4 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,9 @@ You can see a live example here: http://jsfiddle.net/mJMpw/617/ - Use css min/max-width to limit the size. - Use css "transition: width 0.3s;" etc. if you want a nice animation when the width is changed. - Have fun! :) + +Options +------- + +* min: Minimum size for field (default: 0) +* max: Maximum size for field (default: 9999999999) diff --git a/jquery.autosize.input.js b/jquery.autosize.input.js index d4bf181..cfe2d98 100644 --- a/jquery.autosize.input.js +++ b/jquery.autosize.input.js @@ -1,9 +1,18 @@ var Plugins; (function (Plugins) { var AutosizeInputOptions = (function () { - function AutosizeInputOptions(space) { - if (typeof space === "undefined") { space = 30; } - this.space = space; + function AutosizeInputOptions(opts) { + var defaults = { + space: 30, + min: 0, + max: 9999999999 + } + + if (typeof opts === "undefined") { opts = defaults; } + + this.space = opts['space']; + this.max = opts['max']; + this.min = opts['min']; } return AutosizeInputOptions; })(); @@ -58,7 +67,9 @@ var Plugins; var newWidth = this._mirror.width() + this._options.space; // Update the width - this._input.width(newWidth); + if (this._options.max > newWidth && this._options.min < newWidth) { + this._input.width(newWidth); + } }; AutosizeInput.getDefaultOptions = function () {