From 7076343338ae3439f3c86f01144818abe8c31978 Mon Sep 17 00:00:00 2001 From: George Halkiadakis Date: Sun, 12 Mar 2023 07:16:23 +0200 Subject: add container helpers; constuct public directory-tree --- html/content/js/Forms/textarea.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 html/content/js/Forms/textarea.js (limited to 'html/content/js/Forms/textarea.js') diff --git a/html/content/js/Forms/textarea.js b/html/content/js/Forms/textarea.js new file mode 100644 index 0000000..493c78f --- /dev/null +++ b/html/content/js/Forms/textarea.js @@ -0,0 +1,26 @@ +$$plugins.define('textarea', function (element, options) { + const textarea = element.querySelector('textarea'); + + //style focus + textarea.addEventListener('focus', (event) => { + textarea.closest(".textarea").classList.add("focus"); + }); + + textarea.addEventListener('blur', (event) => { + textarea.closest(".textarea").classList.remove("focus"); + }); + + //characters count + textarea.addEventListener("input", event => { + const target = event.currentTarget; + const maxLength = target.getAttribute("maxlength"); + const currentLength = target.value.length; + const currentLengthText = document.getElementsByClassName("textarea__remaining")[0]; + + currentLengthText.innerHTML = currentLength; + + if (currentLength >= maxLength) { + return; + } + }); +}); -- cgit v1.2.3