aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2020-05-23 19:34:00 -0700
committerAllan Wang <me@allanwang.ca>2020-05-23 19:34:00 -0700
commit28c105cb0cc9593930f069584662380a7674c249 (patch)
tree2a340e398beb7b4e5888c49fcbc0f5f7ba88862b
parent7c8e02d385d418ebae1f8f718b72c4170a1bc819 (diff)
downloadfrost-28c105cb0cc9593930f069584662380a7674c249.tar.gz
frost-28c105cb0cc9593930f069584662380a7674c249.tar.bz2
frost-28c105cb0cc9593930f069584662380a7674c249.zip
Add auto resize to text areas
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt1
-rw-r--r--app/src/web/ts/auto_resize_textarea.ts22
3 files changed, 24 insertions, 1 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt
index 03ab6e96..91f8aa71 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt
@@ -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
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt
index 4d635547..657bf93e 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt
@@ -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,
diff --git a/app/src/web/ts/auto_resize_textarea.ts b/app/src/web/ts/auto_resize_textarea.ts
new file mode 100644
index 00000000..f690d4c0
--- /dev/null
+++ b/app/src/web/ts/auto_resize_textarea.ts
@@ -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);