mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-03 00:31:25 -08:00
automatically resize textareas based on contents
This commit is contained in:
parent
01f3cf212b
commit
03f10c36aa
5 changed files with 22 additions and 0 deletions
|
@ -33,6 +33,24 @@ function toggleClass(elementId, className) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function findOutermostParent(element, className) {
|
||||||
|
while (element && !element.classList.contains(className)) {
|
||||||
|
element = element.parentNode;
|
||||||
|
}
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupAutoResize(element) {
|
||||||
|
const elem = document.getElementById(element);
|
||||||
|
elem.addEventListener("keyup", function(event) {
|
||||||
|
const outerWrapper = findOutermostParent(elem, 'downarea');
|
||||||
|
elem.style.height = 'auto'; // Reset height to auto to calculate scrollHeight accurately
|
||||||
|
elem.style.height = (elem.scrollHeight + 2) + 'px'; // Add 2px to avoid cutting off text
|
||||||
|
outerWrapper.style.height = (elem.scrollHeight + 61) + 'px';
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function collapseReply(comment_id) {
|
function collapseReply(comment_id) {
|
||||||
const reply = document.getElementById('comment_' + comment_id);
|
const reply = document.getElementById('comment_' + comment_id);
|
||||||
let isHidden = false;
|
let isHidden = false;
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
resize: DownArea.RESIZE_VERTICAL,
|
resize: DownArea.RESIZE_VERTICAL,
|
||||||
hide: ['heading', 'bold-italic'],
|
hide: ['heading', 'bold-italic'],
|
||||||
});
|
});
|
||||||
|
setupAutoResize('discussion_body');
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
resize: DownArea.RESIZE_VERTICAL,
|
resize: DownArea.RESIZE_VERTICAL,
|
||||||
hide: ['heading', 'bold-italic'],
|
hide: ['heading', 'bold-italic'],
|
||||||
});
|
});
|
||||||
|
setupAutoResize('body');
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
resize: DownArea.RESIZE_VERTICAL,
|
resize: DownArea.RESIZE_VERTICAL,
|
||||||
hide: ['heading', 'bold-italic'],
|
hide: ['heading', 'bold-italic'],
|
||||||
});
|
});
|
||||||
|
setupAutoResize('body');
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
hide: ['heading', 'bold-italic'],
|
hide: ['heading', 'bold-italic'],
|
||||||
value: {{ form.discussion_body.data | tojson | safe }}
|
value: {{ form.discussion_body.data | tojson | safe }}
|
||||||
});
|
});
|
||||||
|
setupAutoResize('discussion_body');
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
Loading…
Add table
Reference in a new issue