From 147b75ce576d48b4e273f1490fa7a9969f7377f9 Mon Sep 17 00:00:00 2001 From: Edmondas Girkantas Date: Wed, 1 May 2024 07:14:56 +0300 Subject: [PATCH] refactor: move textarea autoresize code to separate file, use it in multiple places --- assets/textareaAutoResize.js | 14 ++++++++++++++ templates/add_record.html | 4 +++- templates/edit.html | 18 +----------------- templates/edit_record.html | 4 +++- 4 files changed, 21 insertions(+), 19 deletions(-) create mode 100644 assets/textareaAutoResize.js diff --git a/assets/textareaAutoResize.js b/assets/textareaAutoResize.js new file mode 100644 index 00000000..9ce93490 --- /dev/null +++ b/assets/textareaAutoResize.js @@ -0,0 +1,14 @@ +document.addEventListener('DOMContentLoaded', function() { + var textareas = document.querySelectorAll('textarea'); + + textareas.forEach(function(textarea) { + textarea.addEventListener('input', function() { + this.style.height = 'auto'; + this.style.height = this.scrollHeight + 'px'; + }); + + if (textarea.value !== '') { + textarea.dispatchEvent(new Event('input')); + } + }); +}); diff --git a/templates/add_record.html b/templates/add_record.html index 62baca51..56492ca5 100644 --- a/templates/add_record.html +++ b/templates/add_record.html @@ -67,4 +67,6 @@
{% trans %}Add record to zone{% endtrans %} "{{ zone_name }}" {% trans %}Add also reverse record{% endtrans %} {% endif %} - \ No newline at end of file + + + diff --git a/templates/edit.html b/templates/edit.html index 610d9875..875c3b10 100644 --- a/templates/edit.html +++ b/templates/edit.html @@ -420,20 +420,4 @@
{% trans %}Edit zone{% endtrans %} "{{ zone_name_to_display }}" - \ No newline at end of file + diff --git a/templates/edit_record.html b/templates/edit_record.html index a1b052c3..29d203eb 100644 --- a/templates/edit_record.html +++ b/templates/edit_record.html @@ -82,4 +82,6 @@
{% trans %}Edit record in zone{% endtrans %} "{{ zone_name }}"<       - \ No newline at end of file + + +