1
0
mirror of https://github.com/AllanWang/Frost-for-Facebook.git synced 2024-11-10 04:52:38 +01:00

Add auto resize to text areas

This commit is contained in:
Allan Wang 2020-05-23 19:34:00 -07:00
parent 7c8e02d385
commit 28c105cb0c
No known key found for this signature in database
GPG Key ID: C93E3F9C679D7A56
3 changed files with 24 additions and 1 deletions

View File

@ -35,7 +35,7 @@ import kotlinx.coroutines.withContext
*/
enum class JsAssets : InjectorContract {
MENU, CLICK_A, CONTEXT_A, MEDIA, HEADER_BADGES, TEXTAREA_LISTENER, NOTIF_MSG,
DOCUMENT_WATCHER, HORIZONTAL_SCROLLING
DOCUMENT_WATCHER, HORIZONTAL_SCROLLING, AUTO_RESIZE_TEXTAREA
;
@VisibleForTesting

View File

@ -128,6 +128,7 @@ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() {
),
JsAssets.DOCUMENT_WATCHER,
JsAssets.HORIZONTAL_SCROLLING,
JsAssets.AUTO_RESIZE_TEXTAREA,
JsAssets.CLICK_A,
CssHider.ADS.maybe(!prefs.showFacebookAds),
JsAssets.CONTEXT_A,

View File

@ -0,0 +1,22 @@
// Credits to https://codepen.io/tomhodgins/pen/KgazaE
(function () {
const textareas = <NodeListOf<HTMLTextAreaElement>>document.querySelectorAll('textarea.frostAutoExpand');
const _frostAutoExpand = (el: HTMLElement) => {
el.style.height = 'inherit'
el.style.height = `${el.scrollHeight}px`
};
function _frostExpandAll() {
textareas.forEach(_frostAutoExpand);
}
textareas.forEach(el => {
const __frostAutoExpand = () => {
_frostAutoExpand(el)
};
el.addEventListener('paste', __frostAutoExpand)
el.addEventListener('input', __frostAutoExpand)
el.addEventListener('keyup', __frostAutoExpand)
});
window.addEventListener('load', _frostExpandAll)
window.addEventListener('resize', _frostExpandAll)
}).call(undefined);