// needs JQuery // might actually handle divs too in addition to textareas sS hjs_autoExpandingTextAreas(bool verbose default false) { ret hcss([[ .auto-expand { max-height: 30em; vertical-align: top; } ]]) + hjs(replaceDollarVars([[ var autoExpandVerbose = $verbose; var autoExpandTextArea = function (ta) { ta.style.height = "1px"; // Get the computed styles for the element var computed = window.getComputedStyle(ta); var h = ta.scrollHeight + parseInt(computed.getPropertyValue('border-top-width')) + parseInt(computed.getPropertyValue('border-bottom-width')); if (autoExpandVerbose) console.log("Calculated auto-expand height " + h + " for " + ta); ta.style.height = h + 'px'; }; document.addEventListener('input', function (event) { if (!event.target.classList.contains("auto-expand")) return; autoExpandTextArea(event.target); }, false); //$(document).ready(function() { document.addEventListener("DOMContentLoaded", function(event) { $(".auto-expand").each(function() { autoExpandTextArea(this); }); }); ]], +verbose); }