Files
wordpress-theme-aksrt/assets/js/core/comment-fixed-input.js
T

33 lines
963 B
JavaScript

/**
* Autoheight for comment textarea (legacy parity).
*/
(function () {
'use strict';
// Autoheight textareas.
function bindAutoheight(ta) {
if (!ta || ta.dataset.autoheightBound) return;
ta.dataset.autoheightBound = '1';
var max = parseInt(ta.getAttribute('maxheight') || '188', 10) || 188;
var resize = function () {
ta.style.height = 'auto';
var h = Math.min(ta.scrollHeight, max);
ta.style.height = h + 'px';
ta.style.overflowY = ta.scrollHeight > max ? 'auto' : 'hidden';
};
ta.addEventListener('input', resize);
resize();
}
function scan() {
document.querySelectorAll('textarea[autoheight], textarea.grin').forEach(bindAutoheight);
}
document.addEventListener('DOMContentLoaded', scan);
if (window.AksrtFrontend && typeof window.AksrtFrontend.register === 'function') {
window.AksrtFrontend.register('aksrt-comment-fixed-input', function () {
scan();
});
}
})();