2016-11-17 00:57:01 +08:00
|
|
|
$(document).on(
|
|
|
|
'focus',
|
|
|
|
'textarea.smart-text-area:not([readonly]):not([disabled])',
|
|
|
|
function() {
|
|
|
|
var $this = $(this);
|
2023-05-03 17:31:17 +08:00
|
|
|
var height = $this.height();
|
2016-11-08 22:48:30 +08:00
|
|
|
|
2016-11-17 00:57:01 +08:00
|
|
|
if ($this.hasClass('textarea-sm-present')) {
|
|
|
|
$this
|
2023-05-03 17:31:17 +08:00
|
|
|
.removeClass('textarea-sm-present')
|
|
|
|
.addClass('textarea-sm');
|
2016-11-17 00:57:01 +08:00
|
|
|
$this.attr('rows', '1');
|
|
|
|
} else if ($this.hasClass('textarea-sm')) {
|
|
|
|
// Set the nr. of rows to 1 if small textarea
|
|
|
|
$this.attr('rows', '1');
|
|
|
|
} else {
|
|
|
|
$this.removeAttr('rows');
|
|
|
|
}
|
2016-11-08 22:48:30 +08:00
|
|
|
|
2016-11-17 00:57:01 +08:00
|
|
|
// Initialize autosize plugin if it's not initialized yet
|
|
|
|
if (_.isUndefined($this.data('autosize'))) {
|
2023-05-03 17:31:17 +08:00
|
|
|
$this.autosize({ append: '' });
|
2016-11-08 22:48:30 +08:00
|
|
|
|
2016-11-17 00:57:01 +08:00
|
|
|
// Restore previous height!
|
2023-05-03 17:31:17 +08:00
|
|
|
$this.height(height);
|
2016-11-17 00:57:01 +08:00
|
|
|
}
|
2016-11-08 22:48:30 +08:00
|
|
|
|
2016-11-17 00:57:01 +08:00
|
|
|
$this.trigger('autosize.resize');
|
|
|
|
}
|
|
|
|
);
|