*/
var calculateRows = function(element) {
var currentRows = element.attr('rows');
+ var minRows = element.data('min-rows');
var maxRows = element.attr('data-max-rows');
var height = element.height();
// based on the row attribute.
element.css('height', '');
- if (maxRows && rows >= maxRows) {
+ if (rows < minRows) {
+ return minRows;
+ } else if (maxRows && rows >= maxRows) {
return maxRows;
} else {
return rows;
}
};
+ /**
+ * Listener for change events to trigger resizing of the element.
+ *
+ * @method changeListener
+ * @param {Event} e The triggered event.
+ * @private
+ */
+ var changeListener = function(root, e) {
+ var element = $(e.target);
+ var minRows = element.data('min-rows');
+ var currentRows = element.attr('rows');
+
+ if (typeof minRows === "undefined") {
+ element.data('min-rows', currentRows);
+ }
+ var rows = calculateRows(element);
+
+ if (rows != currentRows) {
+ element.attr('rows', rows);
+ element.trigger(EVENTS.ROW_CHANGE);
+ }
+ };
+
/**
* Add the event listeners for all text areas within the given element.
*
* @public
*/
var init = function(root) {
- $(root).on('input propertychange', SELECTORS.ELEMENT, function(e) {
- var element = $(e.target);
- var currentRows = element.attr('rows');
- var rows = calculateRows(element);
-
- if (rows != currentRows) {
- element.attr('rows', rows);
- $(root).trigger(EVENTS.ROW_CHANGE);
- }
- });
+ if ($(root).data('auto-rows')) {
+ $(root).on('input propertychange', changeListener.bind(this, root));
+ } else {
+ $(root).on('input propertychange', SELECTORS.ELEMENT, changeListener.bind(this, root));
+ }
};
return /** @module core/auto_rows */ {